# 初始化package.json
npm init
# 安装koa2
npm install koa
复制代码
const Koa = require('koa')
const app = new Koa()
app.use( async ( ctx ) => {
ctx.body = 'hello koa2'
})
app.listen(3000)
console.log('[demo] start-quick is starting at port 3000')复制代码
因为koa2是基于async/await操做中间件,目前node.js 7.x的harmony模式下才能使用,因此启动的时的脚本以下:node
node index.js复制代码
访问http:localhost:3000,效果以下git
原文链接:https://github.com/ChenShenhai/koa2-note/blob/master/note/start/quick.mdgithub