1 ---
2 title: Specifying dependencies and devDependencies in a package.json file
3 ---
4
5 To specify the packages your project depends on, you must list them as `"dependencies"` or `"devDependencies"` in your package's [`package.json`][pkg-json] file. When you (or another user) run `npm install`, npm will download dependencies and devDependencies that are listed in `package.json` that meet the [semantic version][semver] requirements listed for each. To see which versions of a package will be installed, use the [semver calculator][semver-calc].
6
7 - `"dependencies"`: Packages required by your application in production.
8 - `"devDependencies"`: Packages that are only needed for local development and testing.
9
10 ## Adding dependencies to a `package.json` file
11
12 You can add dependencies to a `package.json` file from the command line or by manually editing the `package.json` file.
13
14 ### Adding dependencies to a `package.json` file from the command line
15
16 To add dependencies and devDependencies to a `package.json` file from the command line, you can install them in the root directory of your package using the `--save-prod` flag (also `-S`) for dependencies (the default behavior of `npm install`) or the `--save-dev` flag (also `-D`) for devDependencies.
17
18 To add an entry to the `"dependencies"` attribute of a `package.json` file, on the command line, run the following command:
19
20 ```
21 npm install <package-name> [--save-prod]
22 ```
23
24 To add an entry to the `"devDependencies"` attribute of a `package.json` file, on the command line, run the following command:
25
26 ```
27 npm install <package-name> --save-dev
28 ```
29
30 ### Manually editing the `package.json` file
31
32 To add dependencies to a `package.json` file, in a text editor, add an attribute called `"dependencies"` that references the name and [semantic version][semver] of each dependency:
33
34 ```
35 {
36 "name": "my_package",
37 "version": "1.0.0",
38 "dependencies": {
39 "my_dep": "^1.0.0",
40 "another_dep": "~2.2.0"
41 }
42 }
43 ```
44
45 To add devDependencies to a `package.json` file, in a text editor, add an attribute called `"devDependencies"` that references the name and [semantic version][semver] of each devDependency:
46
47 ```
48 "name": "my_package",
49 "version": "1.0.0",
50 "dependencies": {
51 "my_dep": "^1.0.0",
52 "another_dep": "~2.2.0"
53 },
54 "devDependencies" : {
55 "my_test_framework": "^3.1.0",
56 "another_dev_dep": "1.0.0 - 1.2.0"
57 }
58 ```
59
60 [pkg-json]: creating-a-package-json-file
61 [semver]: about-semantic-versioning
62 [semver-calc]: https://semver.npmjs.com/