简体   繁体   中英

one dedicated directory for node_modules

I am quite new to npm but I have a question about npm node modules. I have the node modules now installed in several directories. One for Gulp, one for nodeJS etc. I was wondering how I could have one dedicated node modules directory and let the other packages point to that directory, instead of having node modules all over the place.

What is best practise?

Cheers, Lino

Yes, you can have global node_modules directory accessible to multiple application.
A package is available globally if it is installed with -g option. For instance if body-parser is required globally it should be installed with the following npm command:

npm install body-parser -g

Following are the paths are usage of modules:

  • Local install (default): puts stuff in ./node_modules of the current package root.
  • Global install (with -g): puts stuff in /usr/local or wherever node is installed.
  • Install it locally if you're going to require() it.
  • Install it globally if you're going to run it on the command line.
  • If you need both, then install it in both places, or use npm link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM