liveBook · Manning

Npm install

As explained in Essential TypeScript 5, Third Edition

npm install is an npm command that installs project packages and updates the project's installation metadata.

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

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Explains local and global scope, dependency resolution, metadata sections, and version selection without detailing npm’s internal resolver.
Examples
Uses TypeScript tooling, tsc-watch, and @types/debug to demonstrate project installation and declaration support.
What it assumes
Assumes a project using npm and package.json, while teaching local versus global installs and runtime versus development dependencies.
What you can do after
Operate npm install to restore project packages, add runtime or development dependencies, and install third-party declarations.
How it connects
Connects package.json, node_modules, dependencies, devDependencies, TypeScript, and Definitely Typed declaration files.

Also explained in

Compare how 2 books explain npm install →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Essential TypeScript 5, Third Edition. The section links point to the parts of the book it draws on.