nodejs开发指南中MircoBlog例子中遇到的问题
因为书中的express版本是2.x,而现在已经是3.x了。按照书上的流程走会出现很多问题,本人初学者,不知道该如何修改代码,望高人给点帮助。下面是我的app.js:va...
因为书中的express版本是2.x, 而现在已经是3.x了。按照书上的流程走会出现很多问题,本人初学者,不知道该如何修改代码,望高人给点帮助。下面是我的app.js:var express = require('express') , routes = require('./routes') , user = require('./routes/user') , http = require('http') , path = require('path');var partials = require('express-partials');var MongoStore = require('connect-mongo')(express);var settings = require('./settings/settings');var app = express();app.configure(function(){ app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); app.use(partials()); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser()); app.use(express.session({ secret: settings.cookieSecret, store: new MongoStore({ db: settings.db})}));app.use(app.router); app.use(express.static(__dirname + '/public'));});app.configure('development', function(){ app.use(express.errorHandler());});app.get('/', routes.index);app.get('/u/:user', routes.user);app.post('/post', routes.post);app.get('/reg', routes.reg);app.post('/reg', routes.doReg);app.get('/login', routes.login);app.post('/login', routes.doLogin);app.get('/logout', routes.logout);http.createServer(app).listen(app.get('port'), function(){ console.log("Express server listening on port " + app.get('port'));});
routes\index.js 文件:
module.exports = function(app) {
app.get('/', function(req, res) {
res.render('index', {
title: '首页'
});
});
app.get('/reg', function(req, res) {
res.render('reg', {
title: '用户注册',
});
});
}; 展开
routes\index.js 文件:
module.exports = function(app) {
app.get('/', function(req, res) {
res.render('index', {
title: '首页'
});
});
app.get('/reg', function(req, res) {
res.render('reg', {
title: '用户注册',
});
});
}; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询