出于某种原因,在我的机器上使用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
Express就在那里但在/ 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)
答案 0 :(得分:351)
随着Express 4.0.0的发布,您似乎需要sudo npm install -g express-generator
。
答案 1 :(得分:33)
您需要运行:
npm install -gd express-generator
原来用cli表达,现在将cli分成单独的快速发生器包。最初由项目生成的是运行快递节点app.js,因为httpserver相关代码在app.js中,现在这部分代码到项目目录bin/www
下面,app.js只保留了实现app逻辑代码,你需要运行bin/www
。只是一个非常简单的应用程序和优化包依赖版本更改。
答案 2 :(得分:0)
我经历了好几天的挑战。深入搜索后,我了解到必须阅读所有可用资源,尤其是从父源中读取本资源(在本例中为EXPRESSJS.COM)。这是一个快速修复。
从4.0+版本开始,如果您正在运行Node 8.2+,则不一定需要安装express-generator。只需运行
npx express-generator
express-generator的运行方式与您运行时的运行方式相同:express
有关更多详细信息,请参见Getting Started
快乐的阅读和研究时间。
答案 3 :(得分:0)
我最近一直在尝试安装express-generator,但是它会给出结果,
Session_End
那是我做完之后
$ zsh : command not found : express
但是随后,我看到了npm install commnand的控制台日志
$ sudo npm install -g express
$ sudo npm install -g express-generator
提示可执行文件表达在bin文件夹中。
因此解决方案是: 打开〜/ .zshrc或〜/ .bashrc 并按如下所示导出路径:
/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
现在可以使用。