Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,696 Points

npm install on my machine is defaulting to global

I'm trying to practice some of what I learned in Gulp on my local machine, but when I try and do npm install [module] it defaults to global without me adding the -g flag. It doesn't add a node_modules folder in my local directory.

Maybe I changed some preferences at some point? Trying to read the docs but I can't make sense of it.

2 Answers

Rich Donnellan
Rich Donnellan
25,767 Points

Add the --save flag. Read more at the npm docs.

npm install [module] --save
Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,696 Points

I don't know why I'm struggling so much with this. Here is what I did in my terminal:

  • npm install underscore --save
  • it installs it in what appears to be the global node_modules folder, not local
  • I list the contents of the local folder, there is no node_modules folder
  • npm ls shows all the global modules including underscore
~/test: npm install underscore --save
underscore@1.8.3 ../node_modules/underscore
~/test: ls
~/test: npm ls
/Users/brendan.whiting
├─┬ mongodb@2.1.13
│ ├── es6-promise@3.0.2
│ ├─┬ mongodb-core@1.3.12
│ │ ├── bson@0.4.22
│ │ └─┬ require_optional@1.0.0
│ │   ├── resolve-from@2.0.0
│ │   └── semver@5.1.0
│ └─┬ readable-stream@1.0.31
│   ├── core-util-is@1.0.2
│   ├── inherits@2.0.1
│   ├── isarray@0.0.1
│   └── string_decoder@0.10.31
└── underscore@1.8.3

~/test: 
Rich Donnellan
Rich Donnellan
25,767 Points

Nice! Chances are you won't make the same mistake again! :)

Hi Brendan,

Sorry I could not reply sooner, but glad to hear you have it sorted...

Craig