Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 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. fs.writeFile('./data.json', data.map.name , 'utf-8');
  17. });
  18.  
  19. req.on('end', function () {
  20. console.log("POST payload: " + body);
  21. res.end( '' );
  22. });
  23. }
  24. else
  25. {
  26. console.log("Not expecting other request types...");
  27. res.writeHead(200, {'Content-Type': 'text/html'});
  28. var html = '<html><body>HTTP Server at http://' + host + ':' + port + '</body></html>';
  29. res.end(html);
  30. }
  31. });
  32.  
  33. server.listen(port, host);
  34. console.log('Listening at http://' + host + ':' + port);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement