我正在尝试以下代码,但它给了我一个错误,“res.send不是一个函数”.请帮我.
这是代码:
var http = require('http');
var fs = require('fs');
var connect = require('connect');
var express = require('express');
var app = express();
app.get('/', function(res, req ) {
res.send('Hello World');
});
var server = app.listen(8888, function(){
var host = server.address().address;
var port = server.address().port;
console.log("Example app listening at http://%s:%s", host, port);
});
TypeError: res.send is not a function
at c:\wamp\www\node\server.js:8:13
at Layer.handle [as handle_request] (c:\wamp\www\node\node_modules\express\lib\router\layer.js:95:5)
at next (c:\wamp\www\node\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (c:\wamp\www\node\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (c:\wamp\www\node\node_modules\express\lib\router\layer.js:95:5)
at c:\wamp\www\node\node_modules\express\lib\router\index.js:281:22
at Function.process_params (c:\wamp\www\node\node_modules\express\lib\router\index.js:335:12)
at next (c:\wamp\www\node\node_modules\express\lib\router\index.js:275:10)
at expressInit (c:\wamp\www\node\node_modules\express\lib\middleware\init.js:40:5)
at Layer.handle [as handle_request] (c:\wamp\www\node\node_modules\express\lib\router\layer.js:95:5)
解决方法:
根据API reference,第一个参数是请求,然后是响应
所以
app.get('/', function(req, res) {
res.send("Rendering file")
}
应该解决它.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。