Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

node.js - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...