Skip to content

Commit 9e1d3bc

Browse files
committed
Redirect non-server stdout to stderr
Fixes #1
1 parent 6f1c2f7 commit 9e1d3bc

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

server.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,21 @@ require('babel-register')({
101101
presets: [ 'es2015', 'react' ]
102102
})
103103

104+
// Redirect stdout to stderr, but save a reference so we can
105+
// still write to stdout.
106+
var stdout = process.stdout
107+
Object.defineProperty(process, 'stdout', {
108+
configurable: true,
109+
enumerable: true,
110+
value: process.stderr
111+
})
112+
113+
// Ensure console.log knows about the new stdout.
114+
var Console = require('console').Console
115+
console = new Console(process.stdout, process.stderr)
116+
117+
// Read JSON blobs from stdin, pipe output to stdout.
104118
process.stdin
105119
.pipe(JSONStream.parse())
106120
.pipe(EventStream.map(createRequestHandler(process.cwd())))
107-
.pipe(process.stdout)
121+
.pipe(stdout)

0 commit comments

Comments
 (0)