nats-ex
v1.1.0
Published
Simplify communications on NATS.
Downloads
31
Readme
NATS EX
Simplify communications on NATS.
Features
- JSON-based message protocol
- Auto transfer errors
- ES6 async/await api
Installation
npm i nats-ex
Usage
const {connect} = require('nats-ex')
// connect to nats
const natsEx = await connect({
url: 'nats://localhost:4222',
})
// subscribe a topic
natsEx.on('hello', (name) => {
console.log(`Welcome ${name}`)
return `Hello ${name}`
})
// emit an message
natsEx.emit('hello', 'Bob')
// console: Welcome Bob
// request a response
natsEx.call('hello', 'Alice').then(console.log)
// console: Welcome Alice
// console: Hello Alice
API
Protocol
License
MIT