Ambassador
Ambassador provides a way to communicate between node.js processes.
With ambassador:
- You could send JavaScript object(or other types of variables) between processes
- You could safely kill a process which also contains ambassador.
Installation
npm install ambassador --save
Usage
First of all, ambassador
is an EventEmitter
.
Example
Process A (pid: 14100)
// Listen to signal 'watch'; // So that process A will hang on.;
Process B (pid: 14102)
// Send data to process 14100 (A);
Then, process A will print:
Signal "watch" from process[ 14102 ] with data {abc: 1}
Methods
ambassador.send(pid, signal, data);
Send a signal
signal to the process pid
with data data
ambassador
Returns Number
pid The pid of the target process
String
signal Signal name
mixed
data The data to be sent
ambassador.on(signal, callback)
ambassador
Returns String
signal function(pid, data)
callback The callback function
Number
pid The pid number from which process the signal has been sent.
mixed
data The received data
ambassador.kill(pid)
If the target process contains ambassador
, this method will safely kill that process.