Node JS Tutorial for Beginners #8 - The Node Event Emitter

preview_player
Показать описание
Yo gang, in this Node JS tutorial, I'll be introducing you to the event emitter in the Node core. The event emitter allows us to wire up custom events to our own objects and then emit those events at a later point in time.

----- COURSE LINKS:

---------------------------------------------------------------------------------------------
You can find more front-end development tutorials on CSS, HTML, JavaScript, jQuery, WordPress & more on the channel homepage...

========== JavaScript for Beginners Playlist ==========

============ CSS for Beginners Playlist =============

============== The Net Ninja =====================

================== Social Links ==================

Рекомендации по теме
Комментарии
Автор

if you are using a new version of Node.js
you dont have to require util , just use a class and extend it like the following


const events = require('events');

class Person extends events.EventEmitter{
constructor(name){
super();
this.name = name;
}
}

let james = new Person('james');
let mary = new Person('mary');
let ruy = new Person('ruy');
let people = [james, mary, ruy];

people.forEach(person => {
person.on('speak', msg => {
console.log(person.name + ' said : ' + msg);
});
});

james.emit('speak', 'hey dudes');

MrKentiba
Автор

You have one of the best NodeJS educational material for beginners. Your videos are organized and to the point. I definitely would recommend it.

youssefmohamed
Автор

This is the first video in the series that really made me think to follow along the code and know what's going on.. I missed this feeling

xavicon
Автор

Excellent series so far, you have a way of making these things accessible to us simple folk. I didnt realize how much I needed Node JS until I watched these vids.

darkthrongrising
Автор

Searched everywhere for Node Js tutorials..Found it..Saw it..Loved it..Subscribed it..
Thanks for sharing these vids..

animeshpandey
Автор

Shaun, I think this great tutorial series needs to be updated in accordance with the newer syntax of ES6 as other commenters have pointed out.

kerendn
Автор

util.inherits() seems awfully clunky. Do people still use this notation now that ES6 has more Java-like class syntax? I've always been peeved by the way js uses "function" in place of "class" where there should be made a greater distinction.

daniilzadorozhnyy
Автор

By far the best explaining of node. What is this and why it's there - approach. You don't have to go in dept, there are some more complex tutorials for that.

markodjordjevic
Автор

If you're watching this tutorial now & are using ES6 you might get the error 'Object.setPrototypeOf(ctor.prototype, superCtor.prototype);'. Here's the solution, hope you can make sense out of it, ES6 does not use 'inherits', inteads uses 'extends':

const events = require('events');
const util = require('util');

class Person extends events.EventEmitter{
constructor(name){
super();
this.name = name;
}
}

const joe = new Person('joe');
const gladys = new Person('gladys');
const kaya = new Person('kaya');

const people = [joe, gladys, kaya];


person.on('speak', function(msg){
console.log(person.name + ' says ' + msg);
});
});

joe.emit('speak', 'ES6, the heck!');

JoeTembo
Автор

You deserve more than a million subscriber man.

ninja-gh
Автор

Went through the whole Nodejs essential training on Lynda which was decent, but I have to say your videos are laid out much better. Cheers pal, subbed.

jameswelch
Автор

perfect and up to date node.js so far awesome you got another subscriber

cia
Автор

old but gold! for me it was the jquary example. thanks a lot ninja master. 2023 and still the best explanation about eventemitter🐱‍👤
btw this can be updated in a new video ES6 style!

rojahm
Автор

Concise and to the point! Great Job! Subscribed!

SinghShashiShekhar
Автор

Thanks for explaining how it all links up step by step - really helpful!

sharonweir
Автор

I realize that this is just a demonstration for the event emitter and the util module, but beginners should know that we can achieve the same result of this example using a much simpler way: Just add a function speak() to the prototype of Person.

MustaphaHamoui
Автор

Its super awesome /easy to understand and ultra time saving❤️❤️🔥🔥

vatsalmehta
Автор

First, I would love to thank you for all these valuable, simple to understand tutorials.... The Node.js, on the other hand, is extremely hard to understand unless being used in a real-world project.
Can you please try to give us a one-page app example showing us how to include node.js in the interaction process?!

SafwatGabrplus
Автор

I really enjoyed watching your video. but here I want to ask, why do you use the util module instead of just using classes? is there a difference in usage?. and by watching your video I am very grateful that your video gave me enough understanding for emitter event.

kyoontol
Автор

thanks for this session, as a newbie, Im still confused about the emitter. might need to study harder, thanks Ninja.

zyt