node.jsnpmconfig

Can a custom directory name be used instead of 'node_modules' when installing node packages?


I create a package.json, I run npm install, it works alright. It creates a node_modules directory in my root folder (which I can change by using --prefix option). However, I don't like underscores all that much. I want to change the name of the directory NPM downloads the modules to. I want it to be named nmods or node-modules or something like that.

Bower can do a similar thing by reading the directory property inside a .bowerrc file in the current dir. Is there a way to do the same with NPM?


Solution

  • There is no way to change it. The node_modules folder is actually not specific to NPM, it is part of Node's core module loading system. Seen here in modules/cjs/loader.js.

    Changing it globally as you've mentioned would also potentially break some of the modules you are using too, as modules are sometimes packages with their dependencies already present in node_modules and changing it would cause that to break.