Created
December 22, 2016 00:39
-
-
Save luggage66/261c2f4f164f4357a898234a17ae36e7 to your computer and use it in GitHub Desktop.
Example: running a process and piping output back to web client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { spawn } from 'child_process'; | |
// app is an express server | |
app.get('/some/url/:someOption' function(req, res, next) { | |
let { someOption } = req.params; | |
let commandProcess = spawn('node', ['someScript.js', someOption]); | |
commandProcess.stdout.setEncoding('utf8'); | |
commandProcess.stderr.pipe(process.stderr); | |
commandProcess.stdin.write("something on std in"); | |
commandProcess.stdin.end(); | |
commandProcess.stdout.pipe(res); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment