Reputation: 85
I have installed node.js at my local system (path : C:\Program Files\nodejs). I installed some modules and expected them to be placed in (C:\Program Files\nodejs\node_modules). But, the installed modules are placed at C:\Users\Administrator\AppData\Roaming\npm\node_modules. Is this right or wrong? Can i access these modules globally?
My system platform is windows 7, and my version of node is 0.10.
Upvotes: 6
Views: 20398
Reputation: 3669
Running just npm install
will install all modules into a folder in the current directory called node_modules; all files within the same root directory (even in sibling folders), will check for modules here when you call require. You should install any modules that you wish to require in your project this way.
If you want to install a module from npm globally, you can append the -g
flag. This is usually for command-line tools, which you want to be accessible across multiple projects. An example would be npm install nodemon -g
If you are still confused, I recommend you reference this blog post from the makers of node on global/local installation.
Upvotes: 2
Reputation: 2803
You can find out default paths (user's and global's ones) by command:
npm config list
It is in 'prefix' variable, e.g.:
; userconfig C:\Users\pavel\.npmrc
cache = "C:\\ProgramData\\npm-cache"
prefix = "C:\\ProgramData\\npm"
To change default path have to use the command, e.g.:
npm config set prefix="C:\ProgramData\npm"
Upvotes: 2
Reputation:
The current (January 2018) version of Node.js is 9.4.0, so I'm not sure if it is compatible with your version.
You can set the default global installation path for node_modules by modifying your npmrc file.
Execute in a prompt: npm config list
. It should among other things display a prefix
setting, which is set to your Roaming AppData folder, for example: C:\Users\Administrator\AppData\Roaming\npm
. You can override this setting by executing npm config set prefix C:\Program Files\nodejs\node_modules\npm
.
Now, once you install node_modules globally they will be placed in that directory.
Upvotes: 3
Reputation: 391
By default, any packages you install will install to a global installation directory which is why they are showing up in C:\Users\Administrator\AppData\Roaming\npm\node_modules. If you want to install the packages to your local node_modules folder you will need to type in the following:
npm install (package name) --save-dev
Upvotes: 0