Skip to content

Instantly share code, notes, and snippets.

@chiehwen
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save chiehwen/6f791aa95c1a32a4e557 to your computer and use it in GitHub Desktop.

Select an option

Save chiehwen/6f791aa95c1a32a4e557 to your computer and use it in GitHub Desktop.
An example of a web server written with Node which responds with "Welcome to Node.js World."
// server.js
// Typing node server.js to turn on your Node server.
// include the http module you need
var http = require("http");
// access the createServer method in the http object
http.createServer(function(request, response) {
// tell the server what kind of file is coming at it
response.writeHead(200, {"Content-Type": "text/plain"});
// make the server output a message
response.write("Welcome to Node.js World.");
// End the server interaction
response.end();
}).listen(8888); // listening on port 8888
console.log('Server running at http://127.0.0.1:8888');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment