Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http = require('http');
- fs = require('fs');
- port = 3000;
- host = '127.0.0.1';
- server = http.createServer( function(req, res) {
- if (req.method == 'POST') {
- console.log("Handling POST request...");
- res.writeHead(200, {'Content-Type': 'text/html'});
- var body = '';
- req.on('data', function (data) {
- body += data;
- fs.writeFile('./data.json', data.map.name , 'utf-8');
- });
- req.on('end', function () {
- console.log("POST payload: " + body);
- res.end( '' );
- });
- }
- else
- {
- console.log("Not expecting other request types...");
- res.writeHead(200, {'Content-Type': 'text/html'});
- var html = '<html><body>HTTP Server at http://' + host + ':' + port + '</body></html>';
- res.end(html);
- }
- });
- server.listen(port, host);
- console.log('Listening at http://' + host + ':' + port);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement