npx和npm之间的区别?

JavaScript

JimEva

2020-03-13

我刚刚开始学习React,facebook通过提供以下现成的项目来帮助简化初始设置。
链接到Github上的Facebook帐户:https : //github.com/facebook/create-react-app
如果必须安装框架项目,则必须npx create-react-app my-app在命令行中键入
我想知道为什么Github中的facebook帐户npx create-react-app my-app没有npm create-react-app my-app

第1442篇《npx和npm之间的区别?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

6个回答
路易斯丁神奇 2020.03.13

这是NPX的示例:npx cowsay你好

如果在bash终端中键入该内容,则会看到结果。这样做的好处是npx已临时安装了Cowsay。由于Cowsay未永久安装,因此没有包装污染。这对于要避免包装污染的一次性包装非常有用。

如其他答案中所述,在需要安装(使用npm)软件包并在运行之前对其进行配置的情况下,npx也非常有用。例如,不要使用npm来安装并配置json.package文件,然后调用已配置的run命令,而只需使用npx即可。一个真实的例子:npx create-react-app my-app

十三Itachi 2020.03.13

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

NPX是执行node.js软件包的工具。

全局安装还是本地安装都没有关系。NPX将临时安装并运行它。如果您配置package.json文件并将其包含在脚本部分中,则NPM也可以运行软件包。

因此,请记住这一点,如果您想快速检查/运行节点程序包而不安装本地或全局使用NPX。

npM - Manager

npX - Execute - easy to remember

达蒙西里 2020.03.13

简单定义:

npm -Javascript包管理器

npx-执行npm软件包二进制文件

猪猪Jim 2020.03.13

npx是一个npm软件包运行器(x可能代表eXecute)。通常的用途是临时下载或运行程序包或进行试用。

create-react-app是一个npm软件包,预期在项目的生命周期中只能运行一次。因此,最好使用npx一步安装和运行它。

正如在手册页提到https://www.npmjs.com/package/npxNPX可以运行路径或从node_modules / .bin文件默认情况下的命令。

注意: 通过一些挖掘,我们可以发现create-react-app指向在节点环境中执行的Javascript文件(在Linux系统上可能指向/usr/lib/node_modules/create-react-app/index.js)。 。这只是一个进行某些检查的全局工具。实际设置是由react-scripts完成的,其最新版本已安装在项目中。有关更多信息,请参阅https://github.com/facebook/create-react-app

理查德小胖Harry 2020.03.13

npx 运行包命令而不显式安装。

用例:

  • 您既不想在全球也不能在本地安装软件包。
  • 您无权在全球进行安装。
  • 只想测试一些命令。

句法:

npx [options] [-p|--package <package>] <command> [command-arg]...

包是可选的:

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

更多关于command

Me无敌小哥 2020.03.13

NPX:

From 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.

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android