You are on page 1of 3

Semantic Versioning (npm):

  "dependencies": {
    "mongoose": "^5.10.0",
    "underscore": "^1.10.2"
  }

5.10.0 (Major, minor, patch)

^ means:- major version should be 5 and if updated minor/patches are available, get it downloaded

[“~5.10.0”] ~ means: major should be 5, minor should be 10 and if latest patches are available, get it
download.

Exact version: do not use ^ or ~ then it will download the exact version specified.

Commands:

Npm list (showing list of all dependencies)

Npm list –depth=0 (showing list dependencies without sub hierarchy)

Npm I [package name] (install new package)

Npm view [package name] (Shows package.json file of library

Npm view mongoose dependencies (shows only dependencies part from package.json of mongoose
library

Npm view mongoose versions (showing all the versions of mongoose)

Npm I mongoose@4.7.3 (install specific version)

Npm outdated (shows list of multiple installed versions) if any

Npm update (updates will be installed to maximum minor/patch release)

Npm I –g npm-check-updates (this will install new command npm-check-updates)

Npm-check-updates –u (This will update package.json file to latest update, not installing the latest
version)

Development Dependencies:
These are type of packages that are useful in development but not required in production
So install these type of dependencies like
Npm I jshint –save-dev
In the package.json files these should be showing under development dependencies
Uninstall a package:
Npm uninstall [package_name]
Or
Npm un [package_name]
Global Package:
Npm I –g [package_name]
Npm –g outdated

Publish a package:
1. Create new directory
2. Npm init –yes
3. Create new file index.js
Module.exports.add = function(a, b) { return a + b};

4. Create an account with npm adduser


Or
5. Login with your account npm login
6. Enter username, password, email
7. Npm publish (make sure the name used in package.json file should be unique)

Republish a package:

1. Open index.js
Module.exports.multiply = function(a, b) { return a * b };

2. Change version in package.json


Or
3. Npm version minor (This will automatically change the minor version of package)
4. Npm publish

Useful packages

Nodemon: npm I -g nodemon

Node monitor (no need to restart server after every save)


validator: npm I validator

validator with small v

Used for validations of email addresses, Phone numbers, Soccial Security numbers, Credit Card numbers
etc

You might also like