node.js,错误:找不到模块“express" [英] node.js, Error: Cannot find module 'express'

查看:73
本文介绍了node.js,错误:找不到模块“express"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Node.js 的新手,尝试学习 express 来构建我的第一个 Web 应用程序.我被我的第一个示例代码卡住了,需要一些帮助才能让它运行.在发布这个问题之前,我搜索了堆栈溢出,发现了一些类似的问题,但仍然无法解决.

I am new to Node.js, try to learn express to build my first web application. I got stuck on my very first sample code and need some help to get it running. Before I post this question, I did search on stack overflow, found some similar questions but still could not fix it.

Error: Cannot find module 'express'

我使用的是 ma​​c os 10.8.2.我使用 nvm 安装了 Node.js.

I am using mac os 10.8.2. I have Node.js installed using nvm.

node.js: 0.8.20 path to node:    /Users/feelexit/nvm/v0.8.20/bin/node
path to express: /Users/feelexit/nvm/node_modules/express

这是我的示例代码:此文件位于:

here's my sample code: this file locates at:

/Users/feelexit/WebstormProjects/learnnode/node_modules/index.js

var express = require('express');
var app = express();
app.get('/', function(req, res){
    res.send('welcome to express');
});
app.listen(3000);

当我尝试运行此命令时 node index.js 我收到以下错误消息,请帮我修复它.

when I try to run this command node index.js I get following error message, please help me to fix it.

谢谢.

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/feelexit/WebstormProjects/learnnode/node_modules/index.js:1:81)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
feelexits-Mac:node_modules feelexit$ 

更新回答 chovy 的问题:

feelexits-Mac:~ feelexit$ npm install
npm ERR! install Couldn't read dependencies
npm ERR! Error: ENOENT, open '/Users/feelexit/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Darwin 12.2.0
npm ERR! command "/Users/feelexit/nvm/v0.8.20/bin/node" "/Users/feelexit/nvm/v0.8.20/bin/npm" "install"
npm ERR! cwd /Users/feelexit
npm ERR! node -v v0.8.20
npm ERR! npm -v 1.2.11
npm ERR! path /Users/feelexit/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/feelexit/npm-debug.log
npm ERR! not ok code 0

推荐答案

它说

Cannot find module 'express'

你有安装express吗?如果没有,那么运行这个.

Do you have express installed? If not then run this.

npm install express

并再次运行您的程序.

这篇关于node.js,错误:找不到模块“express"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆