2013-5-10-redis3.md
layout: post category: lessons title: “自己搭建Node+Express+Redis的MVC框架(三)” tagline: “Supporting tagline” tags: [intro, beginner, jekyll, tutorial]
安装Express⌗
- 安装express十分容易
npm install -gd express
- 执行express,生成MVC的框架
express blog
cd blog
npm install
node app
- 打开http://127.0.0.1:3000/,你可以看到Express的
Hello Word
欢迎页面,表示Express已经成功运行。
使用coffee-script开驾驭Express⌗
require "coffee-script"
http = require 'http'
path = require 'path'
express = require 'express'
app = express()
app.configure(->
app.set('port', process.env.PORT || 3000)
app.use(express.logger('dev'))
app.use(express.directory(__dirname + 'public'))
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.favicon())
app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.use(express.bodyParser({keepExtensions: true, uploadDir: './public/resources'}))
app.use(express.methodOverride())
app.use(express.cookieParser())
app.use(express.session({ secret: 'bang590' }))
app.use(app.router)
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }))
app.enable('trust proxy')
)
app.get '/', (req, res) ->
res.send "Hello World!"
port = process.env.PORT or 3000
http.createServer(app).listen app.get('port'), ->
console.log("Express server listening on port " + app.get('port')
Read other posts