Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 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
MOD
Rich Donnellan
Treehouse Moderator 27,696 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,738 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
Treehouse Moderator 27,696 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