Skip to content
Home » npm vs npx

npm vs npx

npm-vs-npx

In this article, we will learn the difference between npm vs npx of Node.js.


npm
npx
  • Node Package Manager.
  • Node  Package  Execute.
    (Also known as Node Package Runner.)

  • Installed with npm.(npm above 5.2.0 version)

    [ npm install -g npx ]

  • It is a CLI tool named as npx.

  • Use to install/Manage packages.
  • Use to eXecute packages.

  • To use a package, need to install it from the npm registry into the system.


    [ Command to install locally: npm install ]
    [ Command to install globally: npm install -g ]
  • No need to install a package into the system. (Directly use a package from the npm registry)

    [ Command to execute directly: npx your-package-name ]

  • It will look for package installed locally or globally in your machine.
  • If a package is installed locally or globally in your machine, it will use that else it will take directly from npm registry.

  • It Increases the node_modules size if we do not need the installed package (incase of testing purpose).
  • It helps reducing the node_modules size if we do not need the installed package (incase of testing purpose).

  • Use package in two ways:

    1. Using the package’s installed path.
    Command: ./node_modules/.bin/your-package

    2. Using package.json
    Add package name under ‘scripts’ section.
    {
         “name”: “your-application”,
         “version”: “1.0.0”,
         “scripts”: {
             “test-package”: “your-package”
         }
    }
    And then execute the package using below command:
    [ npm run test-package ]
  • Directly execute the package using below command:
    [ npx your-package-name ]

I hope this helps you understand the difference between npm vs npx side by side.


References


Related Posts

Visit https://techtalkbook.com to find more related topics.

Happy Coding!!!


Leave a Reply

Your email address will not be published. Required fields are marked *

1 Shares
Tweet
Pin1
Share
Share
Share