Node.js - npm

Updated: 2020-10-13

npm install

Save to package.json - dependencies section:

$ npm install --save <package-name>

Save to package.json - devDependencies section:

$ npm install --save-dev <package-name>

Disable running script

$ npm config set ignore-scripts true

Note that this may cause npm start to fail

npm outdated

Show outdated packages.

$ npm outdated
Package                         Current  Wanted       Latest  Location
gatsby-plugin-react-helmet        1.0.8   1.0.8       2.0.11  hackingnote
gatsby-plugin-sitemap            1.2.14  1.2.25       1.2.25  hackingnote
gatsby-remark-prismjs             2.0.2   2.0.4        2.0.4  hackingnote
gatsby-source-filesystem         1.5.36  1.5.39       1.5.39  hackingnote
gatsby-transformer-remark        1.7.34  1.7.44       1.7.44  hackingnote
katex                             0.9.0   0.9.0  0.10.0-beta  hackingnote
mathjax                           2.7.3   2.7.4        2.7.4  hackingnote
prettier                         1.11.1  1.13.7       1.13.7  hackingnote
prismjs                          1.14.0  1.15.0       1.15.0  hackingnote
react-adsense                     0.0.4   0.0.4        0.0.5  hackingnote
react-mathjax                     0.1.1   0.1.1        1.0.1  hackingnote

npm update

Update a package

$ npm update gatsby

Trouble Shooting

Error:

npm ERR! Unexpected end of JSON input while parsing near '...

Solution:

$ npm cache clean --force

$ sudo npm i npm -g

$ npm install