I pass stdout from the generated command (ffmpeg, this is not important) using an expression, but if the child process does not work, I still get 200.
Is there a way to return 500 if the exit code was nonzero? (I think the headers were sent by then):
const express = require('express'); const { spawn } = require('child_process'); var app = express(); app.get('/video', function(req, res) { var cmd = "ffmpeg"; var args = ["--wat"]; var proc = spawn(cmd, args); res.contentType('video/mp4'); proc.stdout.pipe(res); proc.stderr.pipe(process.stdout); proc.on("exit", code => { console.log("child proc exited:", code);
source share