DEV Community

loading...

Meet Burns: cleaner application events for Node.js

Shalvah
Builder, explorer, writer. APIs, dev tools, automation. Advocate of simple design.
Originally published at blog.shalvah.me Updated on ・1 min read

Hi dev,to community,

I recently published a new version of my NPM package,Burns. Burns is a Node module for writing clean event-driven code and managing your application events easily. It was inspired by Laravel's events and broadcasting systems.

Here's a brief overview of how you use it:

  • First, you define an event handler:
// handlers/order.js

function sendOrderShippedEmail(data)
{
    mailer.sendEmail(`Hi ${data.userName}, Your order ${data.orderId} has been shipped`);
}
Enter fullscreen mode Exit fullscreen mode
  • Then you attach the handler to an event:
let orderHandlers = require('./handlers/order');
burns.registerEvents({
  orderShipped: orderHandlers.sendOrderShippedEmail
});
Enter fullscreen mode Exit fullscreen mode
  • And then dispatch the event when you're ready!
burns.dispatch('orderShipped', {
    orderId: order.id, 
    userName: user.name
});
Enter fullscreen mode Exit fullscreen mode

You can also get your event broadcast (for instance, via Pusher by specifying a few options.

Please do check it out and share your opinions. 😊

Some things I'd like feedback on:

  1. Usefulness of the package. Do you see this package having any real-world applications in your work?
  2. External API. Is the API clear and easy to use?
  3. Documentation. Is the README clear and concise?
  4. (Bonus: Code quality. Any bugs or things I should watch out for?)

Also, if you know of any tools out there that provide similar functions, I'd love to hear about them.

Thanks!

Discussion (2)

Collapse
entrptaher profile image
Md. Abu Taher 👨‍💻

First view looks great.

Any plan to bring redis or multi-server event management into this? So I can declare a job on one server, and dispatch it from another server. Maybe that's not even related to your initial goal for this project :D .

Collapse
shalvah profile image
Shalvah Author

Thanks. Interesting suggestion. No plans yet, but I'll certainly consider it if there's demand (or I'm bored :D )