Koa入门Demo

本文简单介绍如何开始创建一个Koa项目
DEMO地址:https://github.com/tangweikun/koa-start
创建步骤如下:
1、创建hello-world文件

mkdir hello-world

2、进入hello-world目录下

cd hello-world 

3、初始化一个新项目

npm init -y

4、安装koa

npm install koa --save

5、安装nodemon

npm install -D nodemon

6、创建index.js

touch index.js

7、index内容如下

var koa = require('koa');
var app = koa();

app.use(function *(){
this.body = "Hello World";
});

app.listen(3000);

8、修改package.json文件,在scripts里面添加

"script": "nodemon index.js",

9、启动项目,访问http://localhost:3000

npm start
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容