The Question :
640 people think this question is useful
I have just started learning React, and Facebook helps in simplifying the initial setup by providing the following ready-made project.
If I have to install the skeleton project I have to type
npx create-react-app my-app in command-line.
I was wondering why does the Facebook in Github have
npx create-react-app my-app rather than
npm create-react-app my-app?
The Question Comments :
The Answer 1
792 people think this answer is useful
NPM – Manages packages but doesn’t make life easy executing any.
NPX – A tool for executing Node packages.
NPX comes bundled with
NPM by itself does not simply run any package. it doesn’t run any package in a matter of fact. If you want to run a package using NPM, you must specify that package in your
When executables are installed via NPM packages, NPM links to them:
- local installs have “links” created at
- global installs have “links” created from the global
bin/ directory (e.g.
/usr/local/bin) on Linux or at
%AppData%/npm on Windows.
Documentation you should read
One might install a package locally on a certain project:
npm install some-package
Now let’s say you want NodeJS to execute that package from the command line:
The above will fail. Only globally installed packages can be executed by typing their name only.
To fix this, and have it run, you must type the local path:
You can technically run a locally installed package by editing your
packages.json file and adding that package in the
Then run the script using
npm run-script (or
npm run some-package
npx will check whether
<command> exists in
$PATH, or in the local project binaries, and execute it. So, for the above example, if you wish to execute the locally-installed package
some-package all you need to do is type:
Another major advantage of
npx is the ability to execute a package which wasn’t previously installed:
$ npx create-react-app my-app
The above example will generate a
react app boilerplate within the path the command had run in, and ensures that you always use the latest version of a generator or build tool without having to upgrade each time you’re about to use it.
npx command may be helpful in the
script section of a
when it is unwanted to define a dependency which might not be commonly used or any other reason:
"start": "npx email@example.com",
"serve": "npx http-server"
npm run serve
- How to use package installed locally in node_modules?
- NPM: how to source ./node_modules/.bin folder?
- How do you run a js file using npm scripts?
The Answer 2
107 people think this answer is useful
npx is a npm package runner (x probably stands for eXecute). The typical use is to download and run a package temporarily or for trials.
create-react-app is an npm package that is expected to be run only once in a project’s lifecycle. Hence, it is preferred to use npx to install and run it in a single step.
As mentioned in the man page https://www.npmjs.com/package/npx, npx can run commands in the PATH or from node_modules/.bin by default.
The Answer 3
87 people think this answer is useful
NPM is a package manager, you can install node.js packages using NPM
NPX is a tool to execute node.js packages.
It doesn’t matter whether you installed that package globally or locally. NPX will temporarily install it and run it. NPM also can run packages if you configure a package.json file and include it in the script section.
So remember this, if you want to check/run a node package quickly without installing locally or globally use NPX.
npM – Manager
npX – Execute – easy to remember
The Answer 4
50 people think this answer is useful
Web developers can have dozens of projects on their development
machines, and each project has its own particular set of npm-installed
dependencies. A few years back, the usual advice for dealing with CLI
applications like Grunt or Gulp was to install them locally in each
project and also globally so they could easily be run from the command
But installing globally caused as many problems as it solved. Projects
may depend on different versions of command line tools, and polluting
the operating system with lots of development-specific CLI tools isn’t
great either. Today, most developers prefer to install tools locally
and leave it at that.
Local versions of tools allow developers to pull projects from GitHub
without worrying about incompatibilities with globally installed
versions of tools. NPM can just install local versions and you’re good
to go. But project specific installations aren’t without their
problems: how do you run the right version of the tool without
specifying its exact location in the project or playing around with
That’s the problem npx solves. A new tool included in NPM 5.2, npx is
a small utility that’s smart enough to run the right application when
it’s called from within a project.
If you wanted to run the project-local version of mocha, for example,
you can run npx mocha inside the project and it will do what you
A useful side benefit of npx is that it will automatically install npm
packages that aren’t already installed. So, as the tool’s creator Kat
Marchán points out, you can run npx benny-hill without having to deal
with Benny Hill polluting the global environment.
If you want to take npx for a spin, update to the most recent version
The Answer 5
45 people think this answer is useful
npx runs a command of a package without installing it explicitly.
- You don’t want to install packages neither globally nor locally.
- You don’t have permission to install it globally.
- Just want to test some commands.
- Sometime, you want to have a script command (generate, convert something, …) in
package.json to execute something without installing these packages as project’s dependencies.
npx [options] [-p|--package <package>] <command> [command-arg]...
Package is optional:
npx -p uglify-js uglifyjs --output app.min.js app.js common.js
package (optional) command, followed by arguments
Start a HTTP Server : npx http-server
Lint code : npx eslint ./src
# Run uglifyjs command in the package uglify-js
Minify JS : npx -p uglify-js uglifyjs -o app.min.js app.js common.js
Minify CSS : npx clean-css-cli -o style.min.css css/bootstrap.css style.css
Minify HTML : npx html-minifier index-2.html -o index.html --remove-comments --collapse-whitespace
Scan for open ports : npx evilscan 192.168.1.10 --port=10-9999
Cast video to Chromecast : npx castnow http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4
The Answer 6
22 people think this answer is useful
npx – Execute npm package binaries
The Answer 7
11 people think this answer is useful
Here’s an example of NPX in action: npx cowsay hello
If you type that into your bash terminal you’ll see the result. The benefit of this is that npx has temporarily installed cowsay. There is no package pollution since cowsay is not permanently installed. This is great for one off packages where you want to avoid package pollution.
As mentioned in other answers, npx is also very useful in cases where (with npm) the package needs to be installed then configured before running. E.g. instead of using npm to install and then configure the json.package file and then call the configured run command just use npx instead. A real example:
npx create-react-app my-app