Upgrade to Pro — share decks privately, control downloads, hide ads and more …

npm basics

Oona
September 14, 2014

npm basics

Short introduction to npm and its basic commands.

Oona

September 14, 2014
Tweet

Other Decks in Education

Transcript

  1. Image: Denise Nouvion, wearebandits.com * npm doesn’t really stand for

    “Node Package Manager”, but who cares? NPM Node Package Manager*
  2. Npm is a recursive bacronymic abbreviation for "npm is not

    an acronym" What is npm? 1. Image: Denise Nouvion, wearebandits.com
  3. Npm basics • Npm is the official package manager that

    comes pre-installed with Node.js. • A package manager manages assets (i.e. installs, upgrades, removes, manages dependencies) used in a program. • Npm is used to install, uninstall and manage JavaScript modules called packages from the npm registry (https://www.npmjs.org/). • The npm registry is an online repository of npm packages that can be installed from the command line tool. • The npm registry can range from simple helper libraries, like underscore.js, to task runners, like grunt.js.
  4. Definition from npm documentation, https://www.npmjs.org/doc/misc/npm-faq.html#what-is-a-module-. What is an npm package?

    • a) a folder containing a program described by a package.json file • b) a gzipped tarball containing (a) • c) a url that resolves to (b) • d) a <name>@<version> that is published on the registry with (c) • e) a <name>@<tag> that points to (d) • f) a <name> that has a "latest" tag satisfying (e) • g) a git url that, when cloned, results in (a).
  5. Each npm package contains a package.json file which goes typically

    in the root of a package. It tells npm how the package is structured and what to do to install it. myapplication bin myapplication.js lib main.js package.json README.md Example of npm package directory structure
  6. You can create the package.json file interactively by running “npm

    init” in the terminal: https://www.npmjs.org/doc/cli/npm-init.html { "author": "Firstname Lastname", "name": "myapplication", "description": "Describe your program.", "version": "0.0.0", "repository": { "url": "" }, "main": "./lib/main", "bin": { "myapplication": "./bin/myapplication" }, "dependencies": {}, "devDependencies": {}, "optionalDependencies": {}, "engines": { "node": "*" } } Example of package.json file
  7. Install a package locally. cd /path/to/the/project npm install <package name>

    Install packages locally vs. globally Install a package globally. npm install <package name> -g
  8. Update npm. npm update npm update npm -g Other commands

    Check npm version number. npm -v View global settings for npm. npm config list -l
  9. Update package. npm update <package name> Other commands Summary of

    npm commands. npm help Full list of commands. npm -l
  10. Helpful links • https://www.npmjs.org/ • Package Managers: An Introductory Guide

    For The Uninitiated Front-End Developer: http://tech.pro/tutorial/1190/package-managers-an-introductory- guide-for-the-uninitiated-front-end-developer#what_is_npm • Interactive guide for exploring properties of package.json file: http:// browsenpm.org/package.json