0% found this document useful (0 votes)
147 views23 pages

NPM Presentation 2018

This document provides an overview of Node Package Manager (NPM), including what it is, how to install and use packages, and some best practices. NPM is used to install JavaScript packages/tools for use in Node.js projects. It works with package.json to define project dependencies and package-lock.json to ensure consistent dependencies. Common commands include npm install to add packages, npm update to update them, and flags like -D or -S to determine if packages are dependencies or devDependencies. The document recommends committing package.json and package-lock.json while avoiding node_modules/ in version control.

Uploaded by

Alina Ane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views23 pages

NPM Presentation 2018

This document provides an overview of Node Package Manager (NPM), including what it is, how to install and use packages, and some best practices. NPM is used to install JavaScript packages/tools for use in Node.js projects. It works with package.json to define project dependencies and package-lock.json to ensure consistent dependencies. Common commands include npm install to add packages, npm update to update them, and flags like -D or -S to determine if packages are dependencies or devDependencies. The document recommends committing package.json and package-lock.json while avoiding node_modules/ in version control.

Uploaded by

Alina Ane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

NodeJS + NPM

Contents
• What & Why?
• Installing NPM
• Packages
• Package.json
• Package-lock.json
• Useful commands
• Other package managers
• DO’s and DON’ts
What & Why?

• NPM = Node Package Manager

• It installs the packages you want to use and provides a


useful interface to work with them.
Installing NPM

1. Install NodeJS

2. That’s it
Packages
Packages

• Tools built using NodeJS

• Can be installed globally (user folder - default) or


locally (project folder)

• Can be fetched from the NPM Registry or a custom


repo (Git)
Packages

Installing packages globally

• npm install <package_name> —global

• May install other packages (dependencies)


Packages
Installing packages locally

• You need a package.json file

• npm init

• Go through the wizard


Init wizard

You can use npm init —y to bypass the wizard


Packages
Installing packages locally (cont.)
• npm install <package_name>
Example
• npm install underscore

Output
Package.json
Package.json

• Used for portability

• Committed to repository

• Every package is added as a property of the


dependencies field (or devDependencies)
Package.json

• ^ = most recent major version (anything up to 2.0.0)


• ~ = most recent minor version (1.9.x)
• @ = specific version (@1.9.1)
• * = any version
• Other -> check the docs
Package.json

DevDependencies

• Use the —saveDev flag when installing

• Packages used for development purposes, for example


for running tests or transpiling code
Package-lock.json
Package-lock.json

• Introduced in NPM v5
• Ensures that the dependencies remain the same on all
machines the project is installed on
• It should be committed along with package.json
Other useful commands
Other commands

• Npm I -g <package> -> install


• Npm un <package> -> uninstall
• Npm up -> updates all packages
• Npm i <package1> <package2> - installs multiple
packages at once
Other package managers
Other PM

• Bower - old, deprecated by the creators


• Yarn - higher performance, similar to NPM
DO’s and DON’ts
DO’s and DON’Ts
• DO commit both package.json and package-
lock.json to the project repository
• DON’T commit the node_modules folder
• DO pay attention to the dependencies of the package
you want to install
• DON’T install test runners or code transpilers as
dependencies (use —saveDev for that)
• DO use the scripts property in the package.json to
simplify your commands
Let’s use NPM

You might also like