npm (Node Package Manager) installs the packages a TypeScript project needs, including the compiler, development tools, and application libraries. It puts locally installed packages in node_modules and follows each package’s dependencies to download compatible versions. Install npm alongside Node.js; check the installation with npm --version. section 5.3 section 2.1.1
A typical project setup separates development tools from application packages:
- Run npm init --yes in the project folder to create package.json, which tracks added packages. section 14.1
- Run npm install --save-dev typescript@5.0.2 to install the compiler locally and record it under devDependencies. Installing without --save-dev records an application package under dependencies. section 16.1 section 5.3
- Run npm install to install the packages specified in package.json. A global install instead makes a package available outside one project; a local install keeps it project-specific. section 5.3
Set up compiler tools
In a project folder, run npm init --yes, then npm install --save-dev typescript@5.0.2 and npm install --save-dev tsc-watch@6.0.0. The resulting package.json records both tools in devDependencies. A start script can invoke tsc-watch and run the compiled JavaScript with Node.js; npm start runs that script. section 14.1 section 5.3
Listing 14.4 Configuring NPM in the package.json file in the decorators folder
{
"name": "decorators",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsc-watch --onsuccess \"node dist/index.js\""
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"tsc-watch": "^6.0.0",
"typescript": "^5.0.2"
},
"type": "module"
}
The package.json listing shows the start script, local development dependencies, and module-format setting together. section 14.1
Use a local TypeScript installation when building a project toolchain rather than relying on a globally installed compiler. Package versions can be specified exactly or with an accepted range; the version recorded in package.json affects what npm may install. section 16.1 section 5.3




