Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hello World in HTML with NodeJS
<!doctype html>
<html>
<body>
<p>Hello world! Node is awesome, is it not?</p>
</body>
</html>
var http = require('http');
var fileSystem = require('fs');
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(8080);
console.log('Listening at: localhost:8080');
@jfoclpf

This comment has been minimized.

Copy link

commented May 9, 2017

Is there any embedded version, like echo in php?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.