I had been using npm and npx without knowing the difference, but after the lecture where my instructor explained them, I’ve made a quick summary. Understanding what npm and npx are helps to use them effectively.
Contents
- What is npm?
- What is npx?
- Summary
What is npm?
npm stands for Node Package Manager and is a system for managing Node.js packages. It installs, updates, and removes packages as you develop your project.。
Example usage:
To install a package:
npm install ・・・
To uninstall a package:
npm uninstall ・・・
To update a package:
npm update ・・・
When executing scripts, use npm to run tasks specified in package.json:
npm run ・・・
Examples: Commands like npm run dev
or npm run build
.
What is npx?
npx stands for Node Package Execute, a tool for running packages. It can temporarily install and execute a package that isn’t already installed, and it removes the package afterward.
In addition to temporary use, npx can also directly execute installed packages, such as npx ts-node or npx nodemon. This improves convenience in the command line by making tools directly accessible.
Example usage:
npx ・・・
For instance, when running npx create-next-app
, npx installs create-next-app
temporarily for immediate use and then removes it when finished.
Summary
For packages you plan to use long-term, use npm install
to add them to your project dependencies. For one-time commands or temporary packages, use npx, which provides the convenience of automatic cleanup.
This approach minimizes project dependencies, ensuring efficient project management and command execution.
Top comments (0)