app.js
var express = require('express');
var path = require('path');
var http = require('http');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/nodetest1');
var routes = require('./routes');
var users = require('./routes/users');
var app = express.createServer();
app.get('/', routes.index);
app.get('/userlist', routes.userlist);
但问题是,当我请求http://localhost:8081/userlist时,它会给出错误
Error: failed to locate view "error"
路由/ index.js
/* GET Userlist page. */
exports.userlist = function(req, res) {
var db = req.db;
var collection = db.get('usercollection');
collection.find({},{},function(e,docs){
res.render('userlist', {
"userlist" : docs
});
});
};
快递版:2.5.8
答案 0 :(得分:0)
您似乎没有指定视图路径和视图引擎,例如ejs模板和目录视图
var app = express.createServer();
app.set('views', __dirname+'/views'));
app.set('view engine', 'ejs');