Skip to content

Instantly share code, notes, and snippets.

@AmrMekkawy
Last active August 29, 2018 12:27
Show Gist options
  • Save AmrMekkawy/1e2d1137f4c8ab7184af4fb22618badc to your computer and use it in GitHub Desktop.
Save AmrMekkawy/1e2d1137f4c8ab7184af4fb22618badc to your computer and use it in GitHub Desktop.
How to use npm (Node Package Manager)?

How to use npm (Node Package Manager)?


# Go to your project directory
$ cd /path/to/your/project/directory

# Create the package.json file
$ npm init

# (OR) Create the package.json file without asking questions
$ npm init --yes

# Install a package as a dependency ("underscore" for example)
# dependencies are packages required for the application to run
# --save-prod flag is to add the package to your "dependencies" in the package.json file
# you can ignore adding the --save-prod flag as it's the default
$ npm install underscore --save-prod

# (OR) Install a specific version of a package as a dependency 
# (version 1.8.2 of "underscore" for example)
# --save-prod flag is to add the package to your "dependencies" in the package.json file
# you can ignore adding the --save-prod flag as it's the default
$ npm install underscore@1.8.2 --save-prod

# (OR) Install a package as a devDependency ("gulp" for example)
# devDependencies are packages used for development purposes, 
# for example for running tests or transpiling code.
# --save-dev flag is important if you want to add the package to your "devDependencies" in the package.json file
$ npm install gulp --save-dev

# Uninstall a package ("underscore" for example)
# --save flag is important if you want to remove the package from your "dependencies" in the package.json file
# --save-dev flag is important if you want to remove the package from your "devDependencies"
$ npm uninstall underscore --save

# List all installed packages
$ npm list

# Show which packages have updates and can be updated
$ npm outdated

# Update a package ("underscore" for example)
$ npm update underscore

# (OR) We can also execute `npm update` if we have many outdated modules we want to update
$ npm update

# Search for package ("underscore" for example)
$ npm search underscored

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment