GT2/GT2-iOS/node_modules/logfmt/examples/express_pipe_to_stdout.js

22 lines
514 B
JavaScript
Raw Normal View History

2018-02-12 17:26:06 +00:00
var app = require('express')();
var assert = require('assert');
var http = require('http');
var through = require('through');
var logfmt = require('../logfmt');
app.use(logfmt.bodyParserStream());
app.use(logfmt.requestLogger());
app.post('/logs', function(req, res){
if(!req.body) return res.send('OK');
req.body.pipe(through(function(line){
console.log(JSON.stringify(line));
}))
res.send('OK');
})
http.createServer(app).listen(3000);
console.log("Express server listening on port 3000")