您好我正在尝试显示消息:使用路径文件夹/ user.js
中的资源进行响应 exports.list = function (req, res) {
res.send("respond with a resource");
};
但是我在命令提示符下收到错误404.并在url中 localhost:8080 \ user发送响应的地方我收到消息:
无法获取/用户
我的app.js有代码:
var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', routes.index);
app.get('/users', user.list);
http.createServer(app).listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});
我正在处理的例子来自https://www.youtube.com/watch?v=czmulJ9NBP0。时间是1.37.41
答案 0 :(得分:0)
您的路线名为/users
而不是 /user
。因此,请尝试在浏览器中导航到/users
,它应该可以正常工作。