Skip to content

Instantly share code, notes, and snippets.

@lvidal1
Last active December 30, 2016 21:17
Show Gist options
  • Save lvidal1/83c67321390a66e3b79d040846547736 to your computer and use it in GitHub Desktop.
Save lvidal1/83c67321390a66e3b79d040846547736 to your computer and use it in GitHub Desktop.
Setup a basic node-server
/* Previous Considerations
* ------------------------------- */
//a. It is necessary nodejs must be installed on pc/linux or mac.
//b. This server runs on 127.0.0.1:8081. You can access :
// - by console with '$ node main.js'
// - by browser by goint to http://127.0.0.1:8081/
/* The very basic server
* -------------------------------*/
// 1. Import required modules
var http = require("http");
// 2. Create a server
http.createServer(function(request,response){
// Send the HTTP header
response.writeHead(200,{'Content-Type':'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);
console.log('Server Running at http://127.0.0.1:8081');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment