Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kaelzhang/node-ambassador
Ambassador provides a way to communicate between node.js processes
https://github.com/kaelzhang/node-ambassador
Last synced: 17 days ago
JSON representation
Ambassador provides a way to communicate between node.js processes
- Host: GitHub
- URL: https://github.com/kaelzhang/node-ambassador
- Owner: kaelzhang
- License: other
- Created: 2013-08-22T14:42:02.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-10-07T06:02:08.000Z (about 11 years ago)
- Last Synced: 2024-04-15T12:33:01.074Z (7 months ago)
- Language: JavaScript
- Size: 160 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# 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
## UsageFirst of all, `ambassador` is an [`EventEmitter`](http://nodejs.org/api/events.html#events_class_events_eventemitter).
### Example
Process A (pid: 14100)
```js
// 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)
```js
// 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}
## Methods
### ambassador.send(pid, signal, data);
Send a `signal` signal to the process `pid` with data `data`
##### Returns `ambassador`
##### pid `Number`
The pid of the target process
##### signal `String`
Signal name
##### data `mixed`
The data to be sent
### ambassador.on(signal, callback)
##### Returns `ambassador`
##### signal `String`
##### callback `function(pid, data)`
The callback function
##### pid `Number`
The pid number from which process the signal has been sent.
##### data `mixed`
The received data
### ambassador.kill(pid)
If the target process contains `ambassador`, this method will safely kill that process.