npx - 运行 npx 时如何传递内联选项?

标签 npx npm-registry

在不更改工作站的全局 npm 配置或在当前目录中创建 .npmrc 文件的情况下,我想使用私有(private) nexus 注册表运行 npx 包。

那么,是否可以运行 npx带有内联选项(如registry和strict-ssl)的命令(最好是跨平台)?像这样的东西:

npx somerunnablepackage --registry https://mynexus --strict-ssl false

我在 PowerShell/Windows 上尝试了上面的代码片段,但我的注册表没有被命中,它仍然尝试访问默认注册表 ( https://registry.npmjs.org )。

最佳答案

使用

npm_config_registry=https://mynexus npm_config_strict_ssl=false npx somerunnablepackage

参见https://docs.npmjs.com/cli/v10/using-npm/config#environment-variables

Environment Variables

Any environment variables that start with npm_config_ will be interpreted as a configuration parameter. For example, putting npm_config_foo=bar in your environment will set the foo configuration parameter to bar. Any environment configurations that are not given a value will be given the value of true. Config values are case-insensitive, so NPM_CONFIG_FOO=bar will work the same. However, please note that inside scripts npm will set its own environment variables and Node will prefer those lowercase versions over any uppercase ones that you might set. For details see this issue.

Notice that you need to use underscores instead of dashes, so --allow-same-version would become npm_config_allow_same_version=true.

关于npx - 运行 npx 时如何传递内联选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59478656/

相关文章:

javascript - npx 是否寻找全局安装的包?

node.js - 如何使用 npx 从包运行 cli 命令而不进行全局安装

node.js - 即使 prettier 在 devDependancies 中,prettier 命令也不起作用

javascript - npx 和 npm 的区别?

angular - 在企业 Artifactory 中发布 Angular 库

npm - pnpm create、pnpx、dlx 之间有什么区别?

node.js - NPM:更改 package-lock.json 中的注册表

javascript - npm 注册表 json 响应中的用户对象是什么?

javascript - 如何在 package.json 文件中指定项目 npm 注册表

node.js - 如何在 Linux 上的 npm 上修复连接 ENETUNREACH