40

I'm new to node and using npm to both do some node, angular and Express tutorials. I have used bower before in a tutorial. I'm pretty sure I have installed it using -g already as when i run the bower -v command I get back 1.3.3 I am to understand that installing it using -g means, Install this globally so that on the next project I don't have to install it again.

1) Is this correct?

2) When I start working with a new project do I have to initialize bower?

3) Is there any reason I should use install bower --save-dev after I have already installed bower (-g)lobally?

4) What exactly does install bower --save-dev do?

I have searched and get nothing on google or stack over flow when I search "--save-dev".

I really want to understand this and if you help me, it will help me understand installing much more than just bower and how to use those installs. Again, I'm new to the command line for this type of development and new to these technologies, but have some basic understanding.

Eric Bishard
  • 5,201
  • 7
  • 51
  • 75

1 Answers1

48

Using the --save and --save-dev flags when installing will add them to the project's package.json. This allows anyone who might develop on or use the project to install the dependencies as needed with a simple npm install command. By contrast, the -g flag is global only to your local machine.

SamT
  • 10,374
  • 2
  • 31
  • 39
  • 2
    OK, .. so I see the ones that I installed using `--save-dev` inside my `package.json` and those that I did not, ... they are not there. That's a pretty simple explanation. Thanks. So I'm assuming the only implications not using `--save-dev` will have is that my app will be using these packages without them being added to my manifest (so to speak) which is `package.json`. But I'll know, hopefully; when I revisit in 6 months.. and If I open source my project, it would be nice for any dev to know what I was using and be able to install it easily. so I should use `--save-dev` Am I making sense? – Eric Bishard Aug 02 '14 at 07:56
  • 3
    Yes. I personally never use the `-g` flag for that reason. Additionally, using `--save` and `--save-dev` will version lock the modules in the `package.json`. `-g` installs the latest version by default. – SamT Aug 02 '14 at 08:03
  • 14
    Is it possible to use --save-dev and -g together in command? something like... "npm install --save-dev gulp -g" ? – Oneezy May 02 '15 at 02:46
  • 10
    @MrRioku No I don't think this will work. I just tried it using jade on one of my projects, i used 'npm install -g jade --save-dev` it appeared to only have installed in my global directory and not in my project as dev dependency. I think that the -g will negate the --save-dev flag. Let me know if you find out anything to the contrary, I tried rearranging the flags in different orders before and after the jade and nothing seemed to give me different results. – Eric Bishard Aug 23 '15 at 08:15