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!!!


About the Author

Sandeep Agrawal
working @ Kalpavruksh Technologies as Software Engineer. I am a simple and straightforward person adaptable to any environment and work culture. Like to work in a creative and challenging environment using cutting edge technologies where I could constantly learn and successfully deliver solutions to problems.

Be the first to comment on "npm vs npx"

Leave a comment

Your email address will not be published.


*


1 Shares
Tweet
Pin1
Share
Share
Share
%d bloggers like this: