Advertisement
Guest User

Untitled

a guest
May 24th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. http = require('http');
  2. fs = require('fs');
  3.  
  4. port = 3000;
  5. host = '127.0.0.1';
  6.  
  7. server = http.createServer( function(req, res) {
  8.  
  9. if (req.method == 'POST') {
  10. console.log("Handling POST request...");
  11. res.writeHead(200, {'Content-Type': 'text/html'});
  12.  
  13. var body = '';
  14. req.on('data', function (data) {
  15. body += data;
  16. });
  17. req.on('end', function () {
  18. console.log("POST payload: " + body);
  19. res.end( '' );
  20. });
  21. }
  22. else
  23. {
  24. console.log("Not expecting other request types...");
  25. res.writeHead(200, {'Content-Type': 'text/html'});
  26. var html = '<html><body>HTTP Server at http://' + host + ':' + port + '</body></html>';
  27. res.end(html);
  28. }
  29.  
  30. });
  31.  
  32. server.listen(port, host);
  33. console.log('Listening at http://' + host + ':' + port);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement