2015-12-17 113 views
1

你好我想顯示的消息:從文件夾航線資源響應/ user.js的res.Send它導致404錯誤?

exports.list = function (req, res) { 
    res.send("respond with a resource"); 
    }; 

但我得到一個錯誤404在命令prompt.And在URL 本地主機:8080 \用戶,其中發送響應我得到的消息:

不能得到/用戶

我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

您的路線被命名爲/users/user。因此,請嘗試在您的瀏覽器中導航到/users,它應該可以工作。

+0

我建議改爲app.get('/ user',user.list); – Gary

+0

謝謝你..這工作 –