不依赖任何框架,怎样用原生的nodejs向客户端输出json数据
var http = require('http');
var data = {key: 'value', hello: 'world'};
var srv = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(data));
});
srv.listen(8080, function() {
console.log('listening on localhost:8080');
});