What is the meaning of '-save' for NPM install ?

geeksforgeeks.org

NPM (Node Package Manager) is the default package manager employed in JavaScript runtime environment in Node.js. It has a very frequently used command npm install [Package Name] –save. But the fact is there is no difference between npm install [Package Name] and npm install [Package Name] –save in the later version after npm 5.0.0 onwards.

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:

  1. –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.

    1
    npm install --save
  2. –save-prod or -P:

    The following command is introduced in the later version of npm it will perform the same task as the

    1
    --save

    command unless any other command such as

    1
    -D

    or

    1
    -O

    is present.

    1
    npm install --save-prod
  3. –save-dev or -D:

    With

    1
    --save-dev

    or

    1
    -D

    command 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.

    1
    npm install --save-dev
  4. –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.

    1
    npm install --save-optional
  5. –no-save:

    When this command is used with npm install it will not allow the installed packages from being saved into the dependency section.

    1
    npm install --no-save

Note: NPM provides two additional options to save dependencies into package.json file.

  1. –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.

    1
    npm install --save-exact
  2. –save-bundle or -B:

    The following command is also an optional command when

    1
    --save-bundle

    or

    1
    -B

    is used. This will also add the saved dependencies under the bundleDependency list.

    1
    npm install --save-bundle