一、安装脚手架koa-generator
npm install -g koa-generator
创建koa2项目
koa2 project // 创建项目(默认)
koa2 -e koa2-learn // -e使用es引擎创建项目
cd koa2-learn
npm install
// 以上命令成功之后启动项目
$ npm start
> koa2-learn@0.1.0 start E:\GitHub\koa2-learn
> node bin/www
启动成功
npm run dev // 也可启动
关于koa2学习可参考:
https://segmentfault.com/a/1190000020062888
https://www.jianshu.com/p/5ba990127978
二、async await 学习
用同步的写法完成异步的事情
async 用于申明一个 function 是异步的,而 await 用于等待一个异步方法执行完成
await 只能出现在 async 函数中
参考:https://segmentfault.com/a/1190000007535316
写的挺有意思
三、koa2中间件
1、上下文ctx看文档介绍
2、koa执行原理了解、执行先后
四、koa2路由和cookie
koa-router:https://github.com/ZijianHe/koa-router
输入路由:
http://localhost:3000/users
http://localhost:3000/json
测试下页面
cookie/session
koa2提供了cookie的读写方法、文档了解下








网友评论