使用 npm 安装后,在 bash 中找不到 express 命令
刚刚安装了新的 ubuntu 虚拟机来测试节点 按以下顺序安装了东西:
node
mongodb-server
npm
express
mongoose
现在,尝试创建一个新应用程序,我注意到 Express 不能在 shell 中使用。 express -v
返回 express:找不到命令
我像这样安装了 npm
curl http://npmjs.org/install.sh | sudo sh
并且我以这种方式安装了express
npm install express
有什么想法吗?
just installed new ubuntu vm to test around with node
installed things in this order:
node
mongodb-server
npm
express
mongoose
now, trying to create a new app i noticed express cannot be used in the shell.express -v
returns
express: command not found
i installed npm like this
curl http://npmjs.org/install.sh | sudo sh
and i installed express this way
npm install express
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
从express 4.00开始,您还需要安装express生成器:
只有在此之后,您才能将express作为命令运行!
如需确认,请参阅:ExpressJS.com - 迁移到 Express 4
Starting from express 4.00 you also need to install express generator with:
Only after this will you be able to run express as a command!
For confirmation see: ExpressJS.com - Migrating to Express 4
npm install express -g
您需要全局安装它。
Npm 1.0 默认在本地安装模块。因此 bash 可执行文件位于
/node_modules/bin/
中。您可以将该文件夹添加到PATH
中,也可以只全局安装express
,以便它被PATH
拾取npm install express -g
You need to install it globally.
Npm 1.0 installs modules locally by default. So the bash executable lives in
/node_modules/bin/
. You can add that folder toPATH
or you can just installexpress
globally so that it's picked up byPATH
我遇到了这个问题,并通过 Homebrew 安装节点。该问题是由 Homebrew 引起的。
所以我这样做了:
然后使用 nodejs.org 站点上的安装程序安装了节点。
然后我跑了:
瞧,没问题了。
I had this problem and was installing node via Homebrew. The problem was being caused by Homebrew.
So I did:
and then installed node using the installer on the nodejs.org site.
Then I ran:
And voila no problems.
随着 Express 4.0.0 的发布,您似乎需要执行
sudo npm install -gexpress-generator。
With the release of Express 4.0.0 it looks like you need to do
sudo npm install -g express-generator.
编辑 2017-06-29:这个答案已有 6 年以上历史,但仍然获得投票/流量。相反(对于任何有问题的新用户)我会信任< code>NODE_PATH 官方文档 及其有关 REPL 使用的相应内容 在这个答案之前。
与此问题非常相似,节点找不到我的全局快速安装,因此
require('express')
语句将失败。当节点未选择全局安装时,为我解决此问题的方法是确保
NODE_PATH
env。变量设置正确。在 Ubuntu 11.04 上,节点版本为 0.5.0-pre,我的路径是:
因此,为了澄清您可能想要导出上述环境。变量,或者您可以通过执行以下操作来测试上述值:
EDIT 2017-06-29: this answer is 6+ years old, but still gets votes/traffic. Instead (for any new users with problems) I'd trust both
NODE_PATH
official doc and its corresponding bit about REPL usage before this answer.Quite similar to this issue, node was not finding my global express install, so a
require('express')
statement would fail.What fixed this for me, when a global install wasn't being picked up by node was making sure
NODE_PATH
env. variable was is set correctly.On Ubuntu 11.04, with node version 0.5.0-pre, the paths me were:
So, to clarify you might want to export the above env. variable, or you can just test the above values out by doing:
我必须做一些事情的组合:
来自 node.js 模块路径:< /p>
这会设置 bash 配置文件中的文件路径(可以使用
nano .bash_profile
从 Raynos 稍作修改(上图)因为我需要
sudo
:由于我需要
sudo
,对 Fazi(上图)进行了稍微修改:< /p>测试您的应用程序:
参考:http://expressjs.com/en/starter/generator.html
I had to do a combination of things:
From node.js modules path:
This sets the file path in bash profile (can be viewed using
nano .bash_profile
Slightly modified from Raynos (above) since I needed
sudo
:Slightly modified from Fazi (above) since I needed
sudo
:TEST YOUR APPLICATION:
Ref: http://expressjs.com/en/starter/generator.html
如果您运行的是 Windows:
IF you are running windows: