What is KOA?

The next generation Web development framework based on Node.js

A more straightforward way is to use JS to develop API interface services

How to build

1. Create a folder

mkdir koa-test
Copy the code

2. Enter the folder and initialize NPM (enter as prompted)

npm init
Copy the code

3. Create an entry file. In this case, my entry file is app.js

/ / reference koa
const koa=require('koa');
// Create a koA instance
const app=new koa();

// Simple middleware demo
app.use( async (ctx)=>{
 ctx.body='Hello Koa world'
})

// Listen for port 3000 and output information
app.listen(3000.() = >{
  console.log('Startup success! http://localhost:3000')});Copy the code

4. Start

node app.js
Copy the code

A real man never looks back at the explosion, but looks at his watch, and it takes two minutes and 15 seconds!

5. Test

  • Go to http://localhost:3000

  • curl http://localhost:3000

Make your Node app refresh in real time in two simple steps!