What is the meaning of –save for NPM install ?
Before npm 5.0.0, it was necessary to add
--save after package name because it will save the installed package to package.json file in the dependency section. If you are using a recent version of npm save yourself from unnecessary typing and use npm install [Package Name] instead of npm install [Package Name]
--save by default it will add the installed package to the dependency list in the package.json file.
NPM has several commands which are listed below:
- –save or -S: When the following command is used with npm install this will save all your installed core packages into the dependency section in the package.json file. Core dependencies are those packages without which your application will not give desired results. But as mentioned earlier, it is an unnecessary feature in the npm 5.0.0 version onwards.
npm install --save
- –save-prod or -P: The following command is introduced in the later version of npm it will perform the same task as the
--savecommand unless any other command such as
npm install --save-prod
- –save-dev or -D: With
-Dcommand your installed packages will be added to devDependency section of the package.json file. Development dependencies are those packages which only meant for development purpose it will not affect the application’s result.
npm install --save-dev
- –save-optional or -O: When this command is used the install the that packages will be listed under the optional Dependency section of the package.json file. Optional dependencies are those packages which are only used when a particular feature of the application is used and will not be required if that functionality isn’t used.
npm install --save-optional
- –no-save: When this command is used with npm install it will not allow the installed packages from being saved into the dependency section.
npm install --no-save
Note: NPM provides two additional options to save dependencies into package.json file.
- –save-exact or -E: This is an additional or optional command provided by the npm that will save the exact version of the installed packages which are configured at the time of development. It will not download the dependencies from npm’s default server range operator.
npm install --save-exact
- –save-bundle or -B: The following command is also an optional command when
-Bis used. This will also add the saved dependencies under the bundleDependency list.
npm install --save-bundle