Start another node application using node.js?

Use child_process.fork(). It is similar to spawn(), but is used to create entire new instances of V8. Therefore it is specially used for running new instances of Node. If you are just executing a command, then use spawn() or exec(). var fork = require(‘child_process’).fork; var child = fork(‘./script’); Note that when using fork(), by default, … Read more

Difference between ChildProcess close, exit events

Before Node.js 0.7.7, there was only an “exit” event on child processes (and no “close” event). This event would be fired when the child process has exited, and all streams (stdin, stdout, stdout) were closed. In Node 0.7.7, the “close” event was introduced (see commit). The documentation (permalink) currently says: The ‘close’ event is emitted … Read more

Supervisord – Redirect process stdout to console

You can redirect the program’s stdout to supervisor’s stdout using the following configuration options: stdout_logfile=/dev/fd/1 stdout_logfile_maxbytes=0 Explanation: When a process opens /dev/fd/1 (which is the same as /proc/self/fd/1), the system actually clones file descriptor #1 (stdout) of that process. Using this as stdout_logfile therefore causes supervisord to redirect the program’s stdout to its own stdout. … Read more

Running a shell command from Node.js without buffering output

You can inherit stdin/out/error streams via spawn argument so you don’t need to pipe them manually: var spawn = require(‘child_process’).spawn; spawn(‘ls’, [], { stdio: ‘inherit’ }); Use shell for shell syntax – for bash it’s -c parameter to read script from string: var spawn = require(‘child_process’).spawn; var shellSyntaxCommand = ‘ls -l | grep test | … Read more

tech