Node.js+koa2

javascript

浏览数:270

2019-1-8

const Koa = require('koa')
const app = new Koa()
const bodyParser = require('koa-bodyparser')

app.use(bodyParser())

app.use(async (ctx) => {
    if (ctx.url === '/' && ctx.method === 'GET') {
        let html = `
        

This is demo

username: age: website
` ctx.body = html } else if (ctx.url === '/' && ctx.method === 'POST') { let postData = ctx.request.body; ctx.body = postData } else { ctx.body = '

Not find

' } }) app.listen(3000, () => { console.log('demo is run') })