Vishwas always makes the learning process enjoyable by using real-life scenarios. I have seen it in many of his courses, such as in redux toolkit and I could never forget the flow of it thanks to the real-life scenario he provided.
00:09 Events module in Node.js allows working with events and custom event handling 01:01 Events in Node.js mimic day-to-day scenarios 01:52 The Events module in Node.js encapsulates functionality to emit and respond to events. 03:06 Register a listener for an event using the on method. 04:11 Using the events module to dispatch and respond to custom events. 05:16 Event module in Node.js allows registering multiple listeners for the same event 06:33 Event-driven programming in Node.js delays function execution until a certain event occurs. 07:28 The Events Module returns an event emitter class Crafted by Merlin AI.
Note that when you've multiple event handlers for a single event then both of them will be executed one after each so they will be synchronous to each other only (not for any another part of code)
This is quite an incredible channel, and I'm grateful for its existence and your efforts. Nevertheless, 2 comments: 1. Do try to respond people from time to time. I know that it is a lot to ask (no pun intended) but I can assure you that there are content providers who has lots of viewers and yet respond. 2. Vite. I know many people who are mind-blown by Vite. It can be awesome if you'll teach it in your own uniqe and awesome way. Thanks!
Do event listeners respond in the same order as they are defined, or is it random? In the pizza example, could "Serving complimentary drink" appear before "Order received" sometimes? And if so, is there a way to guarantee the order of execution?
this is just like we declare a function first and then call the function on the end jus like think that the ''emit is calling the function '' and ' emitterOn is function declaration '
It's actually the way these methods work. When we use the on() method, for example, like this: on('request', () => {console.log('Hello!')}), the 'request' event is stored in an 'event object'. We are registering a callback function whose purpose is to handle this event. This name (request) serves as a key (event identifier) in an object, and its callback function is the value. So it would look something like this: { request: [ () => console.log('Hello') ] }. These callback functions are sequentially allocated in this 'master or event object' as they are specified in the code. When you emit an event, for example with emit('request'), Node looks for the 'request' key in the event 'object' and executes all the callback functions associated with that key in sequential order and synchronously (synchronous in this case means it calls one function after another). So if the emit method is before the event listeners, it won't be able to execute the callback functions, because they don't exist yet.
00:09 Events module in Node.js allows working with events and custom event handling 01:01 Events in Node.js mimic day-to-day scenarios 01:52 The Events module in Node.js encapsulates functionality to emit and respond to events. 03:06 Register a listener for an event using the on method. 04:11 Using the events module to dispatch and respond to custom events. 05:16 Event module in Node.js allows registering multiple listeners for the same event 06:33 Event-driven programming in Node.js delays function execution until a certain event occurs. 07:28 The Events Module returns an event emitter class Crafted by Merlin AI.
Vishwas always makes the learning process enjoyable by using real-life scenarios. I have seen it in many of his courses, such as in redux toolkit and I could never forget the flow of it thanks to the real-life scenario he provided.
The way you went through the series is awesome. Summary points are helpful to recap it again. Well down and keep doing advanced topics. 👏👏
You are doing a great work. In future please make a series for Express JS, and make rest api project .
00:09 Events module in Node.js allows working with events and custom event handling
01:01 Events in Node.js mimic day-to-day scenarios
01:52 The Events module in Node.js encapsulates functionality to emit and respond to events.
03:06 Register a listener for an event using the on method.
04:11 Using the events module to dispatch and respond to custom events.
05:16 Event module in Node.js allows registering multiple listeners for the same event
06:33 Event-driven programming in Node.js delays function execution until a certain event occurs.
07:28 The Events Module returns an event emitter class
Crafted by Merlin AI.
love learning with you man, thanks a lot for this course!
Thanks for explaining this concept in a way I could understand
Note that when you've multiple event handlers for a single event then both of them will be executed one after each so they will be synchronous to each other only (not for any another part of code)
This is quite an incredible channel, and I'm grateful for its existence and your efforts.
Nevertheless, 2 comments:
1. Do try to respond people from time to time.
I know that it is a lot to ask (no pun intended) but I can assure you that there are content providers who has lots of viewers and yet respond.
2. Vite. I know many people who are mind-blown by Vite.
It can be awesome if you'll teach it in your own uniqe and awesome way.
Thanks!
Thank you. This is exactly what I was looking for. Clear as crystal :)
Really enjoying this great series, welldone 👍🏾👍🏾
Great tutorial! Thanks!! One question: is it possible to create the event in a node server and listen for the event in the client?
Learning is easy now great videos ... Thanks a lot.
Thank you Vishwas
You are doing god's work 🙏 thank you
thanks teacher 21
How do I enable Intellisense for Nodejs built in functions? I get the suggestions for JavaScript functions but not getting them for Nodejs functions ?
You have to pass the optional arguments as strings?
good stuff bro thanks
what is the scope of emitter, can you emit from one file to another?
Do event listeners respond in the same order as they are defined, or is it random? In the pizza example, could "Serving complimentary drink" appear before "Order received" sometimes? And if so, is there a way to guarantee the order of execution?
Yes they respond in the same order it is synchronous
Why do we need event Emitter when we can use simple function and call then whenever necessary ?
its built in and can be exported/imported between modules
tutorial is really good, only thing that was irritating to me was same tone at the end of every sentence
Thanks for your good work but can you please assemble the course into one
Summary: Events allow us to write code in a non-blocking manner.
why emitter.emit should be after emitter.on in the file? I tried to replace and emit didnt work then ...
think of it like arrow functions, if you call it before initialization, that doesn't look right
this is just like we declare a function first and then call the function on the end jus like think that the ''emit is calling the function '' and ' emitterOn is function declaration '
It's actually the way these methods work. When we use the on() method, for example, like this: on('request', () => {console.log('Hello!')}), the 'request' event is stored in an 'event object'. We are registering a callback function whose purpose is to handle this event. This name (request) serves as a key (event identifier) in an object, and its callback function is the value. So it would look something like this: { request: [ () => console.log('Hello') ] }. These callback functions are sequentially allocated in this 'master or event object' as they are specified in the code.
When you emit an event, for example with emit('request'), Node looks for the 'request' key in the event 'object' and executes all the callback functions associated with that key in sequential order and synchronously (synchronous in this case means it calls one function after another). So if the emit method is before the event listeners, it won't be able to execute the callback functions, because they don't exist yet.
Excelent!!!
Thanks
bloody ads are always annoying
awesome!!!
00:09 Events module in Node.js allows working with events and custom event handling
01:01 Events in Node.js mimic day-to-day scenarios
01:52 The Events module in Node.js encapsulates functionality to emit and respond to events.
03:06 Register a listener for an event using the on method.
04:11 Using the events module to dispatch and respond to custom events.
05:16 Event module in Node.js allows registering multiple listeners for the same event
06:33 Event-driven programming in Node.js delays function execution until a certain event occurs.
07:28 The Events Module returns an event emitter class
Crafted by Merlin AI.