Express安装后出现command not found问题

Express安装后出现command not found问题

安装Node.js的web框架Express:npm install -g express,键入命令:express –help,出现提示:sh: express: command not found。明明安装了express,但却告知不能命令运行express。如图

Image

解决方案

在安装express时增加generator参数:

npm install -g express-generator

原因解释

为什么要加上generator呢?

原先的express带cli, 现在把cli拆成了单独的express-generator包. 原先的express运行生成的项目是node app.js, 因为httpserver相关代码都在app.js里, 现在这部分代码移到了项目目录的bin/www下面, app.js只保留实现app的逻辑代码, 你需要去运行那个bin/www。 只是很单纯的细化应用和包依赖的版本变更。

此外,express命令行在AppData\Roaming\npm下面,默认AppData\Roaming\npm在环境变量path里。

3 thoughts on “Express安装后出现command not found问题

  1. Fantastic goods from you, man. I have understand your stuff previous to and you’re just
    too excellent. I actually like what you’ve acquired here, really like what you’re saying and the way in which you
    say it. You make it enjoyable and you still take care of
    to keep it sensible. I can not wait to read far more from you.
    This is actually a tremendous website.

Leave a Reply

Your email address will not be published. Required fields are marked *