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?
When you first install a package to a Node. js project, npm automatically creates the node_modules folder to store the modules needed for your project and the package-lock. json file that you examined earlier. The node_modules folder contains every installed dependency for your project.
Not committing node_modules implies you need to list all your modules in the package. json (and package-lock. json ) as a mandatory step. This is great because you might not have the diligence to do so, and some of the npm operations might break if you don't.
No, everything is in the bundle after you build. You can take the files defined as output (usually whatever is in the "dist" folder) and stick them on whatever static server you want without the need of the supporting node_modules .
On Windows, it's %AppData%\npm . On Unix systems, it's one level up, since node is typically installed at {prefix}/bin/node rather than {prefix}/node.exe . When the global flag is set, npm installs things into this prefix.
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 module.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.
Yarn you can easily achieve this by adding a file called '.yarnrc' with contents like this:
# ./.yarnrc
--modules-folder lib
Next time you run 'yarn' it will create the lib folder and install packages into there instead of into node_modules.
Now if only we could get 'npm install' to be as clever.
There is no way to change it in npm, however, there is an option to configure it in yarn package manager.
yarn install --modules-folder <path>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With