我刚刚开始学习React, Facebook通过提供以下现成的项目来帮助简化初始设置。

如果我必须安装框架项目,我必须在命令行中键入npx create-react-app my-app。

我想知道为什么Facebook在Github有npx create-react-app my-app而不是npm create-react-app my-app?


当前回答

简单的定义:

NPX

npx代表节点包执行,它随npm而来, 当你在5.2.0版本以上安装NPM时,NPX会自动自动的 安装。它是一个npm包运行器,可以执行任何包 你想从NPM注册表中得到的,甚至不需要安装它 包中。

NPM

npm是JavaScript编程语言的包管理器 的默认包管理器 JavaScript运行时环境。它由一个命令行组成 客户端,也叫npm,是一个公共和付费的在线数据库 私人包

其他回答

NPX:

从https://www.futurehosting.com/blog/npx-makes-life-easier-for-node-developers-plus-node-vulnerability-news/:

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 line. 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 aliases? 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 expect. 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 of npm.

下面是一个使用npx创建应用程序的示例

NPX create-react-app project-name——template all

实际上,我尝试了很多方法来解决这个问题,但都失败了,最终全局删除/删除yarn解决了这个问题

只需在命令行终端输入以下命令:

NPM卸载yarn

然后运行下面的命令来安装react starter项目

npx create-react-app

这里有一个NPX的例子:NPX cowsay hello

如果您将其输入到bash终端,您将看到结果。这样做的好处是npx临时安装了cowsay。没有包装污染,因为cowsay不是永久安装的。这对于想要避免包装污染的一次性包装非常有用。

正如在其他回答中提到的,npx在运行前需要安装并配置包的情况下也非常有用(使用npm)。例如,不用使用npm来安装和配置json。包文件,然后调用配置的运行命令,只需使用NPX代替。一个真实的例子: create-react-app my-app

NPM是一个包管理器,你可以使用NPM安装node.js包

NPX是一个执行node.js包的工具。

无论您是在全局还是本地安装该包。NPX将临时安装并运行它。如果你配置了一个包,NPM也可以运行一个包。Json文件,并包括在脚本部分。

所以请记住,如果您想快速检查/运行一个节点包,而不需要在本地或全局安装,请使用NPX。

npM -经理

npX -执行-容易记住