Skip to content

Instantly share code, notes, and snippets.

@kirilkirkov
Last active October 10, 2024 05:52
Show Gist options
  • Save kirilkirkov/cbd0e3b5bfefc35c7d8e31695c60f189 to your computer and use it in GitHub Desktop.
Save kirilkirkov/cbd0e3b5bfefc35c7d8e31695c60f189 to your computer and use it in GitHub Desktop.
Difference between NPM and NPX (NodeJS)

What is the difference between node npm command line and npx command line?

These are two different cli tools as part of your nodejs installation. Their goal is to make our work with JavaScript packages easier. The main difference is that npm is the actual package manager, but npx is used to execute the JavaScript packages.

What is NPM?

NPM means Node Package Manager, this is the default package manager for nodejs. If you have installed nodejs in your machine, then you will have available npm in yours command line\cli (terminal, dos). It interact with the online database (NPM Registry) of npm so to use it you should have available internet connection. This online database has private and public repositories to fetch from. Anybody can publish are package in this repository.

What is NPX?

NPX means Node Package eXecute this is very powerful tool and npm package runner. This cli tool installed with your npm allows you to execute any JS Package which is available in the npm registry for which i mentioned above, without installing it.

To test if you have npx installed on your machine, just open your terminal and write

npx -v

This will show your current installed version of npx if is available, if you see error that the command is not found, just install the tool with

npm install -g npx

-g attribute will install the npx globally and you will have the command from each directory and new open terminal window in your system. NPX is mostly used when wants to run some JS Package only once.

Using of NPM

As i tell you above, npm can download packages to yours machine from the public repository of npm registry.

If you run

npm install package-name
or
npm i package-name

the package will be downloaded to the current directory from which the terminal is opened. With the -g attribute you can install it globally.

Using of NPX

If you wants to run some package, without downloading it, you can just type

npx package-name

For example, if you wants to install tailwindcss, you can do it with

npm install -D tailwindcss

then if you wants your tailwindcss package to make automatically configuration for you, just type

npx tailwindcss init

In this example, the npx command will run the tailwindcss script which will create the tailwind.config.js configuration file.

Create your vu3 startup project with all basic needed dependencies with npx vue3-startup

https://www.npmjs.com/package/start-vue-app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment