Advertisement
Guest User

Untitled

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