简体   繁体   English

如何运行已发布的npm软件包

[英]How to run a published npm package

I just published my first npm package. 我刚刚发布了我的第一个npm软件包。

Let's say the name of the package is auditor-connector. 假设包的名称是auditor-connector。 While developing the package, I was running it as npm start, and running the index.js file in it with certain arguments as follows. 在开发软件包时,我将其作为npm start运行,并使用某些参数在其中运行index.js文件,如下所示。

npm run start arg1 arg2

I do know how to use this package in another project by install ing it, and require 'ing it. 我确实知道如何通过安装该软件包并在另一个项目中使用它,并要求 安装

However, is there a way, I can enable anyone to just run this package as a tool. 但是,有一种方法,我可以使任何人都可以仅将此软件包作为工具运行 Think of it as a tool I would like anyone to run, instead of a library, that I would like someone to use in code. 将其视为我希望任何人都可以运行的工具,而不是我希望有人在代码中使用的库。 I would expect something like the following npm run <name-of-package> <arg1> <arg2> since you would also have to specify the name of the package with the arguments it expects. 我希望像下面的npm run <name-of-package> <arg1> <arg2>因为您还必须使用期望的参数来指定软件包的名称。

There's npx , the npm package manager. npx ,npm软件包管理器。 When you run 当你跑步

npx <name-of-package> <arg1> <arg2> , npx <name-of-package> <arg1> <arg2>

npx checks node_modules for the executable. npx检查node_modules为可执行文件。 If it's not there, npx downloads the package from npm and then executes it. 如果不存在,则npxnpm下载软件包,然后执行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM