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

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

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


当前回答

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使用的包并不是全局安装的,所以你必须担心长期的污染。

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

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

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

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

npM -经理

npX -执行-容易记住

NPM代表节点包管理器。 它预装在Node.js中。NPM有助于将项目中的包作为依赖项来管理。

在使用NPM时,有两种方法将包安装到本地计算机中。

本地:当一个包在本地安装时,它被安装在 ./node_modules/.bin/ 全局:在用户环境中安装全局包 路径。Linux为“/usr/local/bin”,Windows为“AppData%/npm”。

要执行本地安装的包,应该在包中指定。Json脚本块如下所示。

"scripts": {
    "your-package":  "your-package-name"
}

然后,你可以执行这个包:

npm run your-package-name

NPX是一个NPM包执行器。 目前,当你安装NPM 5.2.0或更高版本时,NPX与NPM捆绑在一起。

为什么NPX胜过NPM?

不需要编辑包。带有node_modules路径的Json文件。 您可以直接从命令行执行该工具。

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

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

NPX是一个用于在新项目中创建和执行某些特性的工具 NPM是包含所有库的包管理器