addon-event-emitter
addon-event-emitter copied to clipboard
How to create and use event emitter interface on Node.js add-ons
Event Emitter on Node.js Native Addons using N-API
How to create and use Event Emitter on Node.js Native Addons
Node.js includes an event system which is an implementation of the Observer pattern that is the most common used event pattern in Node.js application and for good reasons: it's incredibly simple and useful.
Anyone who has used Node.js should be familiar with events. This module has the responsability to facilitate the communication between objects of your application.
Much of the Node.js core API modules are built aroud an idiomatic asynchronous event-driven architecture in which certains kinds of objects (called emitter) periodically emit named events that cause Function objects ("listeners") to be called.
Sometimes you need to promote loose coupling system by ensuring that instead of components (modules) referring to each other explicitly, their interaction is handled through an exchange of message using the events. This can help to decouple the systems and improve the module reusability.
Here you can find a collection of examples where I used or implemented event emitter interface in a Node.js Native AddOns.
In each example directory, run:
$ npm install
$ node-gyp rebuild
$ node index.js or npm start
Examples
- Emit event from C++
- Implement a Native Addons object that inherit from Event Emitter
Node.js C / C ++ Addons
Documenttation of Node.js Native Addons
N-API
Documentation for N-API
Node Addon API
Header-only C++ wrapper classes for the ABI-stable Node.js API
Node.js API (N-API) Package
Web resources
- How I ported bcrypt to new N-API
- N-API the next API for Native Addons
- N-API Next generation Node API for native modules
- Speed up Your Node.js App with Native Addons
- Start with N-API
- How to get a performance boost using Node.js native addons
Nicola Del Gobbo
https://www.npmjs.com/~nicknaso
Acknowledgements
Thank you to all people that encourage me every day.
License
Licensed under Apache license V2