Standard folder to put files for bootsrapping a package?


I need to create/download some files as part of the package I’m building. Not really temp files, but part of bootstrapping the functionality. I guess they should best be put inside the package’s folder. Can I get a path for the package itself so I can write out stuff there? Or is there some other established way?



Inside a node module you have the __dirname variable that points to the directory containing the module


@olmokramer Thanks! That doesn’t seem to be entirely true though, it is the folder of the current script, so in my case that is $module/lib. Kindof works but would rather put it relative the package root so stuff doesn’t break if I move code around.

I remember seeing some atom code where someone did something with filesystem of a dependency package, but I can’t seem to find it…


Oh, I guess I could just use:

But it would be even nicer to know which package I’m in without hardcoding the name of my package…


You can walk up the directory path until you find the package.json and read the package name out of there.


In node speak every separate file is a module, but yes I meant the current script.


If your package’s main file is in the same folder as your package, as opposed to the lib subdirectory, then you could populate a variable in your package’s main file, and I guess you could then reference that variable from everywhere?