欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

基于Node.js开发的KoaHub.js的输出json到页面

程序员文章站 2022-05-08 21:57:40
...
基于Node.js开发的KoaHub.js的输出json到页面
koahub-body-res

koahub body res

Format koa's respond json.

Installation

$ npm install koahub-body-res
Use with koa

var app = require('koa')();
var koaRes = require('koahub-body-res');
app.use(koaRes());

this.data = 'This is a body';
this.msg = 'This is a msg';
this.go = 'This is a go url';

output

this.body = {
code: 200,
data: 'This is a body',
msg: 'This is a msg'
}

this.body = {
code: 200,
data: 'This is a body',
msg: 'This is a msg',
go: 'This is a go url'
};

官网:http://js.koahub.com