In Linux there is giving the parents argument to the mkdir command like this:
In this post I am using nodejs 8.x LTS, this major release of nodejs is coming to and end when it comes to its support cycle. Although I have not fiddled with newer versions of node at the time of this writing it would appear that mkdirp style functionality is now baked into node itself in versions of node 10.x+.
So the mkdirp npm package is a user land nodejs package that must be added to a nodejs project. So then a basic example of mkdirp in nodejs will begin by making it part of the project if it is not there all ready.
Just pass the relative or absolute path at which you want the path created if it is not there, followed by a callback that will fire once the path is created or found to exist. This is of course the async version of mkdirp that is provided, and will typically be what is used in mode cases. There is also however a Sync version of the method that is also provided.
mkdirp is great if making a path if it is not there to begin with is all that you care about, however if you are looking for something that will do this, as well as extend and improve the built in node.js file system module, check out fs-extra. In fs-extra a method called fs.ensureDir is added that does the same thing as mkdirp. In addition each file system method returns a promise, but you can also use callbacks as well.
So there is The idea of making ones own mkdirp method as an alternative to using the mkdirp package of any other additional framework that adds support for this and much more such as the case with fs-extra.
looking over the mkdirp source code the basic idea is something like this
You might want to read up more on the native file system module in general, and the mkdir method in nodejs if you have not done so before hand. There is also making sure that functionality like this is not baked into the version of node that you are now using. Again when I last updated this post I was using node 8.x,in later versions of node you might be able to do this with node by itself. In that case you might only want to bother with something like this if supporting older versions of node is impotent to you for whatever the reason.
Ensuring that path is there if it is not is a pretty common task in most projects, if you are not using mkdirp, make sure that you are using some kind of solution for this task. Many frameworks bring this kind of functionality, along with much more so be sure that adding this in is not redundant.