找不到Express命令


137

出于某些原因,在我的计算机上全局安装Express之后,npm install -g express如果我cd进入目录并尝试运行express ,则会收到以下错误:

express: command not found. 

即使我运行它,sudo我仍然会得到相同的输出。我已经针对此问题尝试了多种不同的解决方案,但没有任何效果。我已经安装了节点,通过homebrew它表明堆栈溢出上的某些线程可能是一个问题,所以我完全卸载了节点,并通过nodejs.org上的安装程序进行了重新安装(我现在正在运行v0.10.26),问题仍然存在。

如果我进入/usr/local/lib/node_modulesExpress,但在/ usr / local / bin中,则与Express无关。我不确定这是否是问题,但考虑到该目录中存在其他全局安装的节点程序包的二进制文件,我认为那里可能有问题。

这是我安装时得到的确切输出:

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)

Answers:


359

随着Express 4.0.0的发布,您似乎需要这样做sudo npm install -g express-generator


3
非常感谢您的帮助!我准备在昨晚拉出头发。
Tony Barsotti 2014年

2
sudo不是必需的,但仍然可以使用。stackoverflow.com/questions/4938592/...
StanleyZheng

4
Bummer,甚至没有官方文件提到它。;-)
Azat 2014年

您是如何找到它的,如果文档中没有找到它,我们应该如何学习呢?
Startec 2014年

1
FWIW官方文档确实提到了它[现在?]- expressjs.com/starter/generator.html
Steven R. Loomis

34

您需要运行:

npm install -gd express-generator

原来的cli使用cli,现在的cli分为单独的express-generator程序包。最初由项目生成的是运行快递节点app.js,因为httpserver相关的代码在app.js中,现在这部分代码到项目目录bin/www下面,app.js保留仅实现应用程序逻辑的代码,需要运行bin/www。只是非常简单的应用程序和优化包依赖项版本更改。


2

我经历了几天的挑战。深入搜索后,我了解到必须阅读所有可用资源,尤其是从父源中读取本资源(在本例中为EXPRESSJS.COM)。这是一个快速修复。

从4.0+版本开始,如果您正在运行Node 8.2+,则不必安装express-generator。只需运行

npx express-generator

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

有关更多详细信息,请参阅“ 入门”。

快乐的阅读和研究时间。


1

我最近一直在尝试安装express-generator,但是它会给出结果,

$ zsh : command not found : express

那是我做完之后

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

但是然后,我看到了npm install commnand的控制台日志

/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文件夹中。

因此解决方案是:打开〜/ .zshrc或〜/ .bashrc并导出路径,如下所示:

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

现在可以使用了。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.