It happened too many times that I forgot to add --save
when installing node modules. Is there a way to append this option by default? So that whenever I type npm install <package>
the package is added to dependencies in package.json
.
Asked
Active
Viewed 5,517 times
10

Lukasz Wiktor
- 19,644
- 5
- 69
- 82
3 Answers
36
From npm5 , npm will save by default . https://github.com/npm/npm/issues/5108

Prashant
- 923
- 1
- 11
- 13
23
I found out that npm
has configuration flags. Setting save=true
does exactly what I need. You can add it to .npmrc
file (in user's home directory) or invoke a command:
npm config set save=true

Lukasz Wiktor
- 19,644
- 5
- 69
- 82
2
Mac/Linux
make an alias inside ~/.bash_profile
alias npmi="npm install --save"
//shorter version
alias npmi="npm i -S"
then just type, so that it will automatically save it to package json
npmi mongoose
Windows
same thing, make alias, read more here https://superuser.com/a/49194
doskey npmi=npm i -S $*

Community
- 1
- 1

Medet Tleukabiluly
- 11,662
- 3
- 34
- 69
-
What about Windows users? ;) – Lukasz Wiktor Jun 16 '16 at 07:43
-
Cool. I didn't know about `doskey`. However, your solution is missing `$*` - without it the package name won't be passed as an argument. – Lukasz Wiktor Jun 16 '16 at 09:11
-
I don't have Windows, didn't test it, so referenced to another answer, feel free to improve this answer :) – Medet Tleukabiluly Jun 16 '16 at 09:15
-
1I tested it and it didn't work but thanks to the link you provided I learnt that adding `$*` solves the issue. – Lukasz Wiktor Jun 16 '16 at 09:19
-
1@LukaszWiktor I suggest powershell alias - https://stackoverflow.com/a/24914795/2115619 – Mihail Malostanidis Feb 28 '19 at 21:23