Skip to content

Instantly share code, notes, and snippets.

@brenoferreira
Created February 27, 2012 14:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save brenoferreira/1924265 to your computer and use it in GitHub Desktop.
Save brenoferreira/1924265 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>
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
Copy link

jfoclpf 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