简单的Express.js应用程序运行错误
Simple Express.js application running with error
我尝试创建一个简单的express应用程序serv.js
:
var express = require('express'),
app = express();
app.listen(3000, function() {
console.log('Server is running');
});
和当我运行它node serv.js
,我有错误:
/home/leonid/proj/first/node_modules/express/lib/application.js:119
this._router.handle(req, res, function(err) {
^
TypeError: Cannot call method 'handle' of undefined
at Function.app.handle (/home/leonid/proj/first/node_modules/express/lib/application.js:119:16)
at Server.app (/home/leonid/proj/first/node_modules/express/lib/express.js:28:9)
at Server.EventEmitter.emit (events.js:98:17)
at HTTPParser.parser.onIncoming (http.js:2108:12)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)
at Socket.socket.ondata (http.js:1966:22)
at TCP.onread (net.js:527:27)
如何解决?
你必须为服务器定义一个路由来响应请求。
var express = require('express'),
app = express();
app.get('/hello.txt', function(req, res){
res.send('Hello World');
});
app.listen(3000, function() {
console.log('Server is running');
});
相关文章:
- JavaScript错误:Microsoft JScript运行时错误:应为对象
- 与域在同一台计算机上运行的NODEJS服务器的CORS错误
- 错误“;未处理'错误'事件“;在运行yo发电机之后
- 为什么datetime.strptime在使用Django运行时会抛出错误
- 使用主题运行时portlet liferay时出现Javascript错误
- 从另一个JSAppleScript运行另一个JS AppleScript时出现权限错误
- 我的基于节点的咖啡脚本未运行(错误%1不是有效的应用程序.)
- Ajax Post请求总是运行错误功能,尽管卷曲到相同的url工作正常
- JavaScript新手,但我的函数在Firefox中运行错误
- jquery AJAX对web方法的调用未运行错误函数
- Cucumber样板运行错误
- 如何解决0x800a1391 -微软JScript运行错误在IE
- 读取XML文件,在IE上运行正确,但在Firefox上运行错误
- 阶乘函数运行错误:超过了最大调用堆栈大小
- AJAX正在运行错误函数而不是成功函数
- Angular2简单运行错误
- IndexDB won't运行错误函数
- jQuery Ajax未运行错误
- Microsoft JScript运行错误:'undefined'为空或不是对象
- 简单的Express.js应用程序运行错误