找不到 Express 命令

出于某种原因,在我的机器上使用 npm install -g express全局安装 Express 之后,如果我将 cd安装到一个目录并尝试运行 Express,我会得到以下错误:

express: command not found.

即使我用 sudo运行它,我仍然得到相同的输出。我已经尝试了多种不同的方法来解决这个问题,但没有一个奏效。我通过 homebrew安装了节点,Stack Overflow 上的一些线程指出这可能是一个问题,所以我完全卸载了节点,并通过 nodejs.org 上的安装程序重新安装(我现在运行的是 v0.10.26) ,问题仍然存在。

如果我进入我的 /usr/local/lib/node_modules快递是在那里,但在/usr/local/bin 没有任何关于快递。我不确定这是否是一个问题,但考虑到该目录中有其他全局安装的节点包的二进制文件,我认为可能存在一些问题。

下面是我在安装时得到的输出:

npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/accepts/1.0.0
npm http GET https://registry.npmjs.org/type-is/1.0.0
npm http GET https://registry.npmjs.org/range-parser/1.0.0
npm http GET https://registry.npmjs.org/cookie/0.1.0
npm http GET https://registry.npmjs.org/fresh/0.2.2
npm http GET https://registry.npmjs.org/buffer-crc32/0.2.1
npm http GET https://registry.npmjs.org/send/0.2.0
npm http GET https://registry.npmjs.org/methods/0.1.0
npm http GET https://registry.npmjs.org/cookie-signature/1.0.3
npm http GET https://registry.npmjs.org/utils-merge/1.0.0
npm http GET https://registry.npmjs.org/merge-descriptors/0.0.2
npm http GET https://registry.npmjs.org/escape-html/1.0.1
npm http GET https://registry.npmjs.org/serve-static/1.0.1
npm http GET https://registry.npmjs.org/qs/0.6.6
npm http GET https://registry.npmjs.org/path-to-regexp/0.1.2
npm http GET https://registry.npmjs.org/parseurl/1.0.1
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/cookie/0.1.0
npm http 304 https://registry.npmjs.org/type-is/1.0.0
npm http 304 https://registry.npmjs.org/buffer-crc32/0.2.1
npm http 304 https://registry.npmjs.org/methods/0.1.0
npm http 304 https://registry.npmjs.org/accepts/1.0.0
npm http 304 https://registry.npmjs.org/range-parser/1.0.0
npm http 304 https://registry.npmjs.org/cookie-signature/1.0.3
npm http 304 https://registry.npmjs.org/fresh/0.2.2
npm http 304 https://registry.npmjs.org/serve-static/1.0.1
npm http 304 https://registry.npmjs.org/qs/0.6.6
npm http 304 https://registry.npmjs.org/utils-merge/1.0.0
npm http 304 https://registry.npmjs.org/merge-descriptors/0.0.2
npm http 304 https://registry.npmjs.org/escape-html/1.0.1
npm http 304 https://registry.npmjs.org/path-to-regexp/0.1.2
npm http 304 https://registry.npmjs.org/parseurl/1.0.1
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/send/0.2.0
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/send/0.1.4
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/negotiator
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/send/0.1.4
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/fresh/0.2.0
npm http 304 https://registry.npmjs.org/negotiator
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/fresh/0.2.0
express@4.0.0 /usr/local/lib/node_modules/express
├── methods@0.1.0
├── parseurl@1.0.1
├── utils-merge@1.0.0
├── merge-descriptors@0.0.2
├── escape-html@1.0.1
├── debug@0.8.0
├── cookie-signature@1.0.3
├── range-parser@1.0.0
├── fresh@0.2.2
├── qs@0.6.6
├── buffer-crc32@0.2.1
├── cookie@0.1.0
├── path-to-regexp@0.1.2
├── type-is@1.0.0 (mime@1.2.11)
├── send@0.2.0 (mime@1.2.11)
├── serve-static@1.0.1 (send@0.1.4)
└── accepts@1.0.0 (negotiator@0.3.0, mime@1.2.11)
76951 次浏览

随着 Express4.0.0的发布,看起来你需要做 sudo npm install -g express-generator

你得跑了:

npm install -gd express-generator

原来的快递与 cli,现在的 cli 分裂成独立的快递生成器包。原来由项目生成的是运行快速节点 app.js,因为 httpserver 的相关代码在 app.js 中,现在这部分代码到了项目目录 bin/www下面,app.js 只保留了实现应用逻辑的代码,需要运行 bin/www。只是一个非常简单的应用程序和细化包依赖性版本的变化。

我接受这个挑战好几天了。经过深度搜索,我了解到必须读取所有可用的资源,尤其是来自父源的资源[在本例中为 EXPRESJS.COM ]。这里有一个快速解决办法。

从版本4.0 + 开始,如果您运行的是 Node 8.2 + ,则不一定需要安装 Express-Generator

npx express-generator

Express 生成器将按照您运行时的方式运行: express

有关详细信息,请参阅 开始

阅读和研究愉快。

我最近一直在尝试安装快速发电机,不管它会发生什么,

$ zsh : command not found : express


那是在我杀了他之后

$ sudo npm install -g express
$ sudo npm install -g express-generator


但随后,我看到了 npm install 命令的控制台日志

/usr/local/Cellar/node/13.1.0/bin/express -> /usr/local/Cellar/node/13.1.0/lib/node_modules/express-generator/bin/express-cli.js


它提示可执行表达式在 bin 文件夹中。

所以解决办法是: 打开 ~/. zhrc 或 ~/. bashrc 输出路径如下:

export PATH=/usr/local/Cellar/node/13.1.0/bin:$PATH

现在可以用了。