npm install downloads project packages into the local node_modules folder and records them in package.json. It follows each package’s dependency chain, selecting compatible versions and downloading everything required. Use local installs for project-specific tools and application packages; global installs make a package available from anywhere. section 5.3
Choose the command according to the package’s role and the version scope you need:
- npm install installs the packages already specified in package.json. section 5.3
- npm install package@version installs a specific package version and adds it to dependencies. section 5.3
- npm install --save-dev package@version adds a development-only package to devDependencies, such as a compiler or watch tool. section 5.3
- npm install --global package@version installs a package for access from anywhere rather than for one project. section 5.3
Installing TypeScript declarations
For a JavaScript package that lacks usable declarations, install its Definitely Typed package as a development dependency: npm install --save-dev @types/debug. The declaration package is placed under node_modules/@types, where the compiler can locate it. Running tsc --traceResolution can confirm which declaration file was selected. section 15.3.4
{
"name": "tools",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"tsc-watch": "^6.0.0",
"typescript": "^5.0.2"
}
}
A package.json listing shows how npm install records development tools such as typescript and tsc-watch under devDependencies. section 5.3

