简体   繁体   中英

i want to create node_modules folder outside my server side folder in nodejs

我创建了服务器端文件夹,其中有node_modules和package.json。我想做的就是将node_modules文件夹移到服务器文件夹之外。我的文件夹结构如下:server node_modules控制器package.json

you can set path for npm_packages.

please find below example - its done on linux, similarly, you might have to do things on your platform

mkdir "${HOME}/.npm-packages"
nano $HOME/.bashrc
NPM_PACKAGES="${HOME}/.npm-packages"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"
unset MANPATH
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
#Save and exit
nano $HOME/.npmrc
prefix=${HOME}/.npm-packages
#Save and exit
source ~/.bashrc

UPDATE: i haven't used windows for quite sometime, but what you should do is -> set NPM_PACKAGES in your $PATH(env etc) also add NPM_PACKAGES onto NODE_PATH . next you edit .npmrc and add a prefix in here, something like prefix=${HOME}/.npm-packages

also please follow these links

Specify path to node_modules in package.json

How to change node_modules path in windows

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