mesg-js
Website - Docs - Forum - Chat - Blog
mesg-js is the official JavaScript library to interact with MESG Engine.
This library can be used from an Application or a Service.
Status
Contents
Installation
npm i mesg-js
Service
Require mesg-js as a service:
const service = const mesg =
Task
The service have to call mesg.listenTask
to start listening for task to execute by passing an object containing the tasks' key and function.
mesg
The task functions accept inputs
as parameter and returns the outputs
as object or Promise of object.
The task function can throw an Error in case of error. The lib will catch it and send it to the MESG Engine.
Event
To emit an event, the service should call the mesg.emitEvent
function with the event's key and event's data as parameters. This function returns a Promise
.
mesg
Application
Require mesg-js as an application:
const application = const mesg =
MESG Engine endpoint
By default, the library connects to the MESG Engine from the endpoint localhost:50052
.
Resolve SID
Instead of hard-coding instanceHash
in your application's env, your application can resolve dynamically using the service's SID.
const instanceHash = await mesg const result = await mesg
Listen events
Listen events from a service.
const instanceHash = await mesg mesg
Listen results
Listen results from a service.
const instanceHash = await mesg mesg
Execute task
Execute task on a service.
const instanceHash = await mesg const execution = await mesgconsole
Execute task and wait result
Execute task on a service and wait for its result.
This can be considered as a shortcut for using both executeTask()
and listenResult()
at same time.
const instanceHash = await mesg const result = await mesgif resulterror console throw resulterrorconsole
Community
You can find us and other MESG users on the forum. Feel free to check existing posts and help other users of MESG.
Also, be sure to check out the blog to stay up-to-date with our articles.
Contribute
Contributions are more than welcome.
If you have any questions, please reach out to us directly on Discord.