Skip to content

Instantly share code, notes, and snippets.

@LautaroJayat
Last active January 26, 2020 19:20
Show Gist options
  • Select an option

  • Save LautaroJayat/3df206bc1af245649f0e14f42ccaa8a2 to your computer and use it in GitHub Desktop.

Select an option

Save LautaroJayat/3df206bc1af245649f0e14f42ccaa8a2 to your computer and use it in GitHub Desktop.
index.js - first encounter with a buffer
const http = require('http');
// Require the File System Module
const fs = require('fs');
const PORT = process.env.PORT || 3000;
const server = http.createServer((req, res) => {
const URL = req.url;
if (req.url === '/') {
// We try to read the method in a Synchronous way
const page = fs.readFileSync('./views/index.html');
// Let output what is in there
console.log(page);
// Make the response
res.writeHead(200);
res.write(page, () => {
console.log('console.log from the callback function!')
});
res.end();
}
}).listen(PORT);
server.on('listening', () => { console.log('We are listening on', PORT) });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment