npm is the command-line package manager installed with Node.js. It connects a project to the online npm repository, where you can find libraries and tools instead of writing every feature yourself. For a Node.js microservice, it creates project metadata and installs dependencies such as Express. section 2.3 section 2.5.4 section 2.6.2
Start in a terminal:
- Create a project directory, change into it, and run `npm init -y`. The `-y` option accepts defaults instead of asking interactive questions; npm creates `package.json`. section 2.6.1
- Run `npm install express` to add Express. npm installs the package under `node_modules` and records it as a dependency in `package.json`. section 2.6.2
- When working from an existing project, run `npm install` in its directory to install its dependencies. section 2.6.2
`package.json` holds project metadata, scripts, and top-level dependencies. npm generates and updates it, but you can edit it by hand. Dependency entries can specify a version or a range; dependencies of dependencies are handled automatically. The older `--save` option makes dependency tracking explicit, but it is no longer required. section 2.6.1 section 2.6.2
Listing 2.2 The package file with Express installed
{
"name": "example-1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
--snip--
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^5.0.0-beta.1" #1
}
}
Inspect the `dependencies` entry to see how an installed Express version is recorded in `package.json`. section 2.6.2
Check `node --version` and `npm --version` after installing Node.js. For production work, keep the Node.js version used in development aligned with production. section 2.5.4




