# 初始化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