简体   繁体   中英

How to replace NPM node_module folder with another folder?

By default of NPM is installing the modules under "node_modules". Is there a way to change it to be for example "my_modules?

The standard for all node modules is to use the node_modules directory.

Do not try to go against this uniform standard.

What are you trying to accomplish by customizing the directory?


Note:

The following command will install a module to my_project/node_modules/some_module

[~/my_project] $ npm install some_module

If you'd like to install modules and have them globally available on your system, you can use the --global ( -g ) flag

[~/my_project] $ npm install -g some_module

Packages installed with the -g flag are installed to ~/.npm


EDIT

Per your comment, you can attempt to install any directory that contains a package.json file

[~/my_project] $ npm install /path/to/my/pkg

Alternatively you can install a symbolic link instead of copying the entire module to your ~/my_project/node_modules directory.

[~/my_project] $ npm link /path/to/my/pkg

For more info about this:

$ npm help install
$ npm help 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