Node JS Create Server


/ Published in: JavaScript
Save to your folder(s)

Node create server with request response


Copy this code and paste it in your HTML
  1. var http = require("http");
  2. var path = require("path"),
  3. var url = require("url"),
  4. var server = http.createServer(function(request, response) {
  5.  
  6. var method = request.method;
  7. var my_path = url.parse(request.url).pathname;
  8. var full_path = path.join('/delete',my_path);
  9.  
  10. response.writeHead(200, {"Content-Type": "text/html"});
  11. response.write("<!DOCTYPE "html">");
  12. response.write("<html>");
  13. response.write("<head>");
  14. response.write("<title>Hello World Page</title>");
  15. response.write("</head>");
  16. response.write("<body>");
  17. response.write("Hello World!");
  18. response.write("</body>");
  19. response.write("</html>");
  20. response.end();
  21. });
  22.  
  23. server.listen(80);
  24. console.log("Server is listening");

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.