【问题标题】:How to start my globally installed node application?如何启动我全局安装的节点应用程序?
【发布时间】:2016-09-30 19:12:13
【问题描述】:

我开发了一个小应用程序。

我这样做是为了在全球范围内安装开发的模块:

npm install . -g

我收到了这样的回复:

$ npm install -g .
update-deps-dev@1.0.0 C:\Users\Vladislav.Sharikov\AppData\Roaming\npm\node_modul
es\update-deps-dev

我的模块就位,其他全局安装的模块都存储在其中。此外,我的模块可通过以下方式获得:

npm ls -g --depth=0

现在,我想从我电脑上的任何地方启动这个模块。我该怎么做?

我尝试运行,但得到了这个:

Vladislav.Sharikov@PC /D/Dev
$ update-deps-dev
sh: update-deps-dev: command not found

我正在使用 Windows 7 x64 + Git Bash。

我应该如何启动我的全局安装的节点应用程序?

我的package.json 文件内容:

{
  "name": "update-deps-dev",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "adm-zip": "^0.4.7",
    "fs": "0.0.2",
    "https": "^1.0.0",
    "q": "^1.4.1",
    "shelljs": "^0.7.0"
  }
}

【问题讨论】:

  • 看起来您还没有在包文件中定义 bin 字段。可以发一下吗?
  • 是的,没有指定。我会尽快发布 package.json。可能有一些文章节点应用程序(节点包/节点模块)必须有什么以及为什么?

标签: node.js windows git-bash


【解决方案1】:

不确定 git bash。但是以跨平台的方式,您可以简单地在您的包 json 上定义一个 bin 字段,以告诉 npm 稍后在您的命令行上生成一个可用的二进制文件。它在 windows、mac、linux 上运行良好。

请注意,它是每个用户的二进制文件。如果您在 linux 上工作,它不会将其安装到 /usr/bin,但取决于您的系统,更可能是 ~/node_modules/bin

假设你的二进制文件被定义到bin.js文件中,你只需要添加一个新的Object字段bin,并且foreach bin你要定义一个key,二进制文件的名字,它的值必须指向你的 bin 文件相对于包文件的路径:

{
  "name": "update-deps-dev",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "bin": {
    "update-deps-dev": "./bin.js"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "adm-zip": "^0.4.7",
    "fs": "0.0.2",
    "https": "^1.0.0",
    "q": "^1.4.1",
    "shelljs": "^0.7.0"
  }
}

另请阅读,

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-10
    • 1970-01-01
    • 2019-08-01
    • 2023-04-05
    • 1970-01-01
    • 2015-03-21
    • 1970-01-01
    • 2022-12-14
    相关资源
    最近更新 更多