Skip to content

Try our new Crash Courses!

Buy one of our new Crash Courses, now hosted on Teachable.

Install package locally – npm

Summary

To install a package locally as a normal dependency, enter the following command in your terminal:

npm install package-name

To install a package locally as a devDependency, enter the following command in your terminal:

npm install package-name --save-dev

Details

Install dependency

To install a regular dependency, you can use the npm install command. For example, if you were trying to install the clipboard package, you would enter the following command in your terminal:

npm install clipboard

This will install the package (and all of its dependencies) in your node_modules folder and add the package to your list of dependencies inside of your package.json file, like this (your version number might be different):

  "dependencies": {
    "clipboard": "^2.0.4"
  }

If this is the first package you’re installing in your project it will automatically create the node_modules folder. You will also see a package-lock.json file added to your project folder if this is the first package you’re installing.

Use this command to install packages that are meant to be used in production.

Install devDependency

To install a devDependency, you can use the npm install command with a --save-dev flag. For example, if you were trying to install the browser-sync package as a devDependency, you would enter the following command in your terminal:

npm install browser-sync --save-dev

This will install the package (and all of its dependencies) in your node_modules folder and add the package to your list of “devDependencies” inside your package.json file, like this (your version number might be different):

  "devDependencies": {
    "browser-sync": "^2.26.7"
  }

If this is the first package you’re installing in your project it will automatically create the node_modules folder. You will also see a package-lock.json file added to your project folder if this is the first package you’re installing.

You should use this command to install packages that are only meant to help with development.

Exercises

Run the following command to install browser-sync in your project folder:

npm install browser-sync --save-dev

Reference

Downloading and installing packages locally | npm Documentation

Back to: npm Reference > npm Local Packages