You have an async logic flow error here.  The `mkdirp` call is asynchronous, but you assume that it will have ended in time to do the `stat`.  That's not necessarily true.  Instead, you need to do any code that depends on the outcome of `mkdirp` into its callback.