JavaScript - Simple Node Server

/** * Put code in server.js * * ------------------------------------ * * To run server: * * $ node server.js * * To open webpage: * * $ open http://localhost:8080 * * ------------------------------------ */ // HTTP module var http = require('http'); // port to listen on const PORT=8080; // handle requests function handleRequest(request, response){ // send response response.end('Hello. ' + request.url); } // create server using request handler var server = http.createServer(handleRequest); // start the server server.listen(PORT, function(){ // callback for listening console.log("Node server listening on: http://localhost:%s", PORT); });

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.