Skip to content

Instantly share code, notes, and snippets.

@lepture
Last active December 20, 2015 05:09
Show Gist options
  • Save lepture/6076491 to your computer and use it in GitHub Desktop.
Save lepture/6076491 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var path = require('path');
var http = require('http');
var bind = 9090;
var basedir = '';
var server = http.createServer(function(req, res) {
if (req.method === 'POST') {
var d = new Date();
if (month < 10) {
month = '0' + month;
}
var filename = d.getFullYear() + '-' + month + '-' + d.getDate() + '.txt';
var s = fs.createWriteStream(path.join(basedir, filename), {flags: 'a'});
s.on('open', function(fd) {
fs.write(fd, '\n');
});
req.pipe(s);
req.on('end', function() {
res.writeHead(200);
res.end('Ok');
});
} else {
res.writeHead(200);
res.end('Ok');
}
});
server.listen(bind);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment