Last active
January 26, 2020 19:20
-
-
Save LautaroJayat/3df206bc1af245649f0e14f42ccaa8a2 to your computer and use it in GitHub Desktop.
index.js - first encounter with a buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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