1server.get('/', (req, res) => {
2 const user = { name: 'Hero', isLearning: true, level: 'apprentice' };
3 return res.json(user);
4})
1var http = require('http');
2
3var app = http.createServer(function(req,res){
4 res.setHeader('Content-Type', 'application/json');
5 res.end(JSON.stringify({ a: 1 }));
6});
7app.listen(3000);
8
9// > {"a":1}