Last active
March 20, 2026 09:08
-
-
Save abonello/43782e019237ed4ea4fd1fa67149980f to your computer and use it in GitHub Desktop.
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <h1>Server</h1> | |
| </body> | |
| </html> |
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') | |
| const fs = require('fs') | |
| const port = 3000 | |
| const server = http.createServer(function(req, res) { | |
| //res.write('Hello World') | |
| res.writeHead(200, { 'Content-Type': 'text/html' }) | |
| fs.readFile('index.html', function(error, data) { | |
| if (error) { | |
| res.writeHead(404) | |
| res.write('Error: File not found') | |
| } else { | |
| res.write(data) | |
| } | |
| res.end() | |
| } | |
| // res.end() | |
| }) | |
| server.listen(port, function(error) { | |
| if (error) { | |
| console.log('Something went wrong', error) | |
| } else { | |
| Console.log('Server is listening on PORT:', port) | |
| } | |
| } | |
| // To run server use: node NodeServer.js |
Comments are disabled for this gist.