简体   繁体   中英

Why does npm install keep saving under node modules folder even though i changed directory to another folder?

In terminal, I entered the command cd /Users/MyUserName/Google/Google Drive/Coding then entered the command npm install underscore . So I figured the underscore module would be saved under my Coding folder; however, it keeps saving under the directory: /Users/MyUserName/node_modules/

How do I change the setting so that when ever I change my directory in terminal and enter a npm install command, the module gets installed in the respective changed directory?

From the documentation :

Starting at the $PWD , npm will walk up the folder tree checking for a folder that contains either a package.json file, or a node_modules folder. If such a thing is found, then that is treated as the effective "current directory" for the purpose of running npm commands. (This behavior is inspired by and similar to git's .git-folder seeking logic when running git commands in a working dir.)

If no package root is found, then the current folder is used.

So it seems the package is installed under your home folder because it already contains a node_modules folder. If you remove that the install should go into the current folder.

Alternatively: Add a node_modules folder to the current folder.

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