Skip to content

Instantly share code, notes, and snippets.

@labra
Last active October 20, 2016 16:26
Show Gist options
  • Save labra/0d413e0fdefbaf4caa094e98c272d391 to your computer and use it in GitHub Desktop.
Save labra/0d413e0fdefbaf4caa094e98c272d391 to your computer and use it in GitHub Desktop.
const http = require('http');
const fs = require('fs');
var personas;
fs.readFile("personas.json",'utf8', (err,datos) => {
if (err) throw err;
json = JSON.parse(datos);
console.log("Total personas:" + json.total);
personas = json.personas;
servidor();
});
function servidor() {
var server = http.createServer()
server.on('request',procesa);
server.listen(3000);
}
var procesa = function (req, res) {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(personas));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment