Skip to content

Instantly share code, notes, and snippets.

@ezsimple
Forked from brenoferreira/index.html
Last active February 10, 2022 02:08
Show Gist options
  • Save ezsimple/5874e4ec9020ccd2a647379d40913000 to your computer and use it in GitHub Desktop.
Save ezsimple/5874e4ec9020ccd2a647379d40913000 to your computer and use it in GitHub Desktop.
Hello World in HTML with NodeJS
<!doctype html>
<html>
<body>
<p>Hello world! Node is awesome, is it not?</p>
</body>
</html>
const http = require('http');
const fileSystem = require('fs');
const host = '0.0.0.0'
const port = 8888
var server = http.createServer(function(req, resp){
fileSystem.readFile('./index.html', function(error, fileContent){
if(error){
resp.writeHead(500, {'Content-Type': 'text/plain'});
resp.end('Error');
}
else{
resp.writeHead(200, {'Content-Type': 'text/html'});
resp.write(fileContent);
resp.end();
}
});
});
server.listen(port, host);
console.log('Listening at: ', host, port);
server.listen(8080);
console.log('Listening at: localhost:8080');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment