Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

node.js - NPM Installs Package Outside Current Directory

I try to install express package using npm from inside /home/iwan/my-project directory:

npm install express

express@3.3.7 ../node_modules/express
├── methods@0.0.1
├── cookie-signature@1.0.1
├── range-parser@0.0.4
├── fresh@0.2.0
├── buffer-crc32@0.2.1
├── cookie@0.1.0
├── debug@0.7.2
├── send@0.1.4 (mime@1.2.11)
└── commander@1.2.0 (keypress@0.1.0)

The strange thing is npm doesn't install express package in current dir (/home/iwan/my-project/node_modules/express), but in /home/iwan/node_modules/express.

Did i miss something?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If the node_modules directory doesn't exist in your current directory, NPM will look for it in the higher directories until it finds it. So, if the parent directory has a node_modules directory, NPM will assume that's where it is to install modules.

A quick way around this is to create an empty node_modules directory where you want the modules to be placed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...