我刚刚开始学习React, Facebook通过提供以下现成的项目来帮助简化初始设置。
如果我必须安装框架项目,我必须在命令行中键入npx create-react-app my-app。
我想知道为什么Facebook在Github有npx create-react-app my-app而不是npm create-react-app my-app?
我刚刚开始学习React, Facebook通过提供以下现成的项目来帮助简化初始设置。
如果我必须安装框架项目,我必须在命令行中键入npx create-react-app my-app。
我想知道为什么Facebook在Github有npx create-react-app my-app而不是npm create-react-app my-app?
当前回答
NPX是一个用于在新项目中创建和执行某些特性的工具 NPM是包含所有库的包管理器
其他回答
另一方面,npx使用的包并不是全局安装的,所以你必须担心长期的污染。
NPM是用来安装包的工具,NPX是用来执行包的工具。 如果你想通过npm运行一个包,那么你必须在你的包中指定这个包。并在本地安装它。 npx-一个包不需要安装就可以执行。它是一个npm包运行器,所以如果任何包还没有安装,它会自动安装它们。
NPM vs NPX
NPM代表节点包管理器。一个基于文本的Nodejs包管理程序。
而NPX是一个节点包运行器。它的功能是执行Nodejs包
NPX将执行Nodejs包中的二进制文件,无论是否安装。
甚至NPX也可以帮助我们使用某些版本的Nodejs,而不必使用nvm (node.js版本管理)、nave (node.js虚拟环境)和nvm (node.js版本管理)。
包管理器
npx -执行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.