liveBook · Manning

Npm

As explained in Web Components in Action

npm is a package manager and software registry for JavaScript and Node.js packages.

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

How Web Components in Action covers it

How deep it goes
Defines installations, dependencies, package.json, and scripts, but only gestures toward larger build systems.
Examples
Demonstrates installing http-server globally, adding Web Components polyfills, initializing package.json, and defining a test script.
What it assumes
Assumes terminal access and Node.js installation while teaching project package management through basic commands.
What you can do after
Operate/configure npm to install packages, record dependencies, distinguish development dependencies, and run package.json scripts.
How it connects
Connects npm with Node.js, package.json, polyfills, build processes, Webpack, Grunt, and Gulp.

Also explained in

Compare how 5 books explain npm →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Components in Action. The section links point to the parts of the book it draws on.