npm is the Node.js ecosystem’s package manager for installing JavaScript packages and supporting frontend development workflows. It can provide tools such as a local HTTP server, project dependencies, and runnable scripts. section 2.6 section 12.3
Use npm to:
- Install a command-line tool globally when it should be available from anywhere, such as http-server. section 2.6
- Install project dependencies into node_modules and record them in package.json. section 12.3
- Separate development-only packages with --save-dev, keeping them distinct from production dependencies. section 12.3
- Run repeatable tasks through the scripts object in package.json without adopting a complex build system. section 12.3
Start a local development server
Install http-server globally with npm install http-server -g. In a project directory, run http-server; the command serves the directory at local HTTP addresses so a browser can load its HTML, CSS, and JavaScript files. section 2.6
Listing 12.7. A simple package.json script
{
"name": "wcia",
"version": "1.0.0",
"scripts": {
"test": "echo 'Hello from package.json'" #1
}
}
A minimal package.json script shows how npm can expose project commands through a named script such as test. section 12.3




