标签:
那个那个MEAN的书,看得七七八八,有了大概,现在就要一样一样的加深记忆啦。。
EXPRSS.JS的东东,网上有现成入门书籍:
第一期代码测试:
var express = require(‘express‘); var app = express(); var handlebars = require(‘express3-handlebars‘) .create({defaultLayout: ‘main‘}); app.engine(‘handlebars‘, handlebars.engine); app.set(‘view engine‘, ‘handlebars‘); app.set(‘port‘, process.env.PORT || 3000); app.use(express.static(__dirname + ‘/public‘)); var fortunes = [ "Conquer your fears or they will conquer you.", "Rivers need springs.", "Do not fear what you don‘t know.", "You will have a pleasant surprise.", "Whenever possible, keep it simple.", ]; app.get(‘/‘, function(req, res) { res.render(‘home‘); }); app.get(‘/about‘, function(req, res) { var randomFortune = fortunes[Math.floor(Math.random() * fortunes.length)]; res.render(‘about‘, {fortune: randomFortune}); }); app.use(function(req, res) { res.status(404); res.render(‘404‘); }); app.use(function(err, req, res, next) { console.error(err.stack); res.status(500); res.render(‘500‘); }); app.listen(app.get(‘port‘), function() { console.log(‘Express started on http://localhost: ‘ + app.get(‘port‘) + ‘; press Ctrl-C teminate.‘); });
书和输出:
标签:
原文地址:http://www.cnblogs.com/aguncn/p/5173942.html