Monday, 20 September 2021

npm install and npx

npm install

If it is a new project and does not have package.json, do

npm init

module will be added as dependencies in package.json

npm install express --save 

module will be added as devDependencies in package.json

npm install mocha --save-dev

module will not be added to dependencies list and install it temporarily

npm install express --no-save

If we want to install modules listed in package.json and respect package-lock.json

npm ci 

npx

npx is package runner tool that comes with npm 5.2

  • If module is installed, npx can run command in the bin directory of the module
  • If module is not installed, when you run npx , the module will be installed and then be cleaned

Some examples


npx happy-birthday -u leo
npx create-react-app my-app

For the above examples, we are running happy-birthday and create-react-app runner tools. npx has other functionalities. For details, see Kat Marchán blog for npx

npm upgrade package

install tools to check package

npm install -g npm-check-updates

To check

npx ncu

To fix patches

npx ncu -u -t patch

To fix minor version

npx ncu -u -t minor

To fix main version

npx ncu -u -f react-datepicker 

All these fix command will only change package.json. To instll, run:

 npm install

No comments:

Post a Comment