Npm

From Logic Wiki
Jump to: navigation, search


to list all the packages and their dependencies with their version numbers

npm list

if we only want to list first level of packages

npm list --depth=0

To see the meta data of a package

npm view packageName

To see just the dependencies of a package

npm view packageName dependencies

Updating local packages

to list which updates are available

npm outdated 

to update minor and patch

npm update

to update majors first install this

sudo npm i -g npm-check-updates 

to see available updates run

npm-check-updates

to update package.json

npm-check-updates -u
ncu -u

install dependencies

npm i

Developer Dependencies

npm i jshint --save-dev

if a package is installed with --save-dev it will only be available in dev env. and not goes to production env.

Uninstall a package

npm un packagename

Upgrade npm

sudo npm i -g npm 

Publishing NPM Packages

first create a npm user

npm adduser 

login

npm login 

enter username, password and email run

npm publish

Publishing scoped packages

npm init --scope=@MyOrganisation
npm publish --access public

Updating a published package

Change the version number either manual (See Semantic Versioning or by npm command like

npm version patch 

or

npm version minor

or

npm version major

then run npm publish to publish the updates in the package


See Also Semantic Versioning