Ambassador provides a way to communicate between node.js processes
OTHER License
Ambassador provides a way to communicate between node.js processes.
With ambassador:
npm install ambassador --save
First of all, ambassador
is an EventEmitter
.
Process A (pid: 14100)
// Listen to signal 'watch'
require('ambassador').on('watch', function(pid, data){
console.log('Signal "watch" from process[', pid, '] with data', data);
});
// So that process A will hang on.
require('http').createServer(function(){}).listen(9876);
Process B (pid: 14102)
// Send data to process 14100 (A)
require('ambassador').send(14100, 'watch', {
abc: 1
});
Then, process A will print:
Signal "watch" from process[ 14102 ] with data {abc: 1}
Send a signal
signal to the process pid
with data data
ambassador
Number
The pid of the target process
String
Signal name
mixed
The data to be sent
ambassador
String
function(pid, data)
The callback function
Number
The pid number from which process the signal has been sent.
mixed
The received data
If the target process contains ambassador
, this method will safely kill that process.