Learn about the npm package manager and command line tool.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Class: The npm Package System


The npm command line tool allows us to work with packages. You can even use it as a build tool. The npm package server provides a place to publish and consume packages created by authors all over the world. In this class you'll learn how an npm package is structured and what we can do with packages in a Node.js application.

What's in this class?

  • Introduction: The npm Package System - What exactly is a package manager? In this lesson you'll learn what constitutes the npm package system. Then we'll review how the Node.js runtime finds packages using the module system.

  • Creating Packages - In this lesson you'll create your own package to learn how packages are structured. I'll start by creating an account on npm. Then I'll show you how to create a package.json file using the npm init command. Then we'll make us of name-spacing so our package name doesn't conflict with other packages on npm. Once we've given the package a little functionality you'll see how to use the npm link command to test it locally.

  • Publishing Your Package - Now that we're done creating a basic package we'll publish it to the npm servers so others can make use of it.

  • Managing Dependencies - Packages usually have dependencies on other packages. In this lesson you'll see how to install dependencies and specify versions of those dependencies in the package.json file using semver versioning. We'll be installing and using the chalk package to give our program some color. Finally, you'll see how to use the npm outdated and npm update commands to keep our package dependencies up to date with our semver specification.

  • Creating Executables - Npm packages can install runnable programs. In this lesson you'll see how to create an executable that users of your package can use just like any other command line tool. We'll start off by creating a command line tool and giving it executable permissions. Then we'll use the npm link command to install it locally so we can test it out.

  • Scripts in Package.json - Npm allows us to specify scripts in the package.json file which makes it useful as a build tool or even as a general utility for running project scripts. For example, you might want to always run your program through the babel compiler, and you can do that inside an npm start script.

  • Additional Resources - Learn how to get help with npm command line tool as well as how to navigate the online documentation.