I just tried deploying node app on a "production" environment.
I use PM2 for running the app by using this command. pm2 start app.js --name <appname>
My questions are:
console.log
of the child_process
I forked?child_process.fork
?EDIT 1
Basically, what the app do is watching a folder using chokidar
.
When there's a new file, it will check the file type, then it will do one of the following items:
.FLV
the app will add a document to a MongoDB collection hosted in mLab..PNG
the app will upload the file to S3 bucket using child_process.fork
..MP4
the app will upload the file to S3 bucket using child_process.fork
, then run and FFmpeg
command to generate a screenshot that runs on another child_process.fork
which then trigger process number 2
above, it also does a MongoDB update on another child_process.fork
.This is the code snippets
1. Chokidar Watcher (app.js)
EDIT 2
Added code snippets for how I use chokidar and forking a child process.
To get the children's stdout and stderr to use the parent's pipe, you need to tell it to do so as part of the spawn command. This is explained in the docs:
https://nodejs.org/api/child_process.html#child_process_child_stdio
It's fine to spawn other processes as needed, subject to whatever system limits you have, though code sample seems to just spawn one at a time.