Node Events Tutorial | Node.js Tutorials for Beginners

  Рет қаралды 31,802

Dave Gray

Dave Gray

Күн бұрын

Web Dev Roadmap for Beginners (Free!): bit.ly/DaveGrayWebDevRoadmap
In this Node events tutorial, you will learn about the events common core module and how to create an Event Emitter. The Node.js Tutorials for Beginners series takes you from zero knowledge of Node JS to building a web server.
🚩 Subscribe ➜ bit.ly/3nGHmNn
🚀 This lesson is part of a Node.js for Beginners tutorial series playlist:
• Node.js Tutorials for ...
Node Events Tutorial | Node.js Tutorials for Beginners
(00:00) Intro
(00:05) Welcome
(00:14) Overview
(00:25) Setup
(01:21) Building a custom log module
(06:33) Events module and EventEmitter
(09:40) Finishing the logEvents module
(14:25) Wrap up
📚 References:
Node.js Official site: nodejs.org
NPM Official site: www.npmjs.com/
✅ Follow Me:
Twitter: / yesdavidgray
LinkedIn: / davidagray
Blog: yesdavidgray.com
Reddit: / daveoneleven
Was this tutorial about events and the Event Emitter in Node.js helpful? If so, please share. Let me know your thoughts in the comments.
#node #nodejs #events

Пікірлер: 55
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Learning how to create an event logger is very useful for a backend application running on Node JS. In this tutorial, we'll cover the Event Emitter in Node.js and create an event logger. If you are just starting to learn Node.js, I recommend starting at the beginning of this Node.js for Beginners playlist: kzbin.info/aero/PL0Zuz27SZ-6PFkIxaJ6Xx_X46avTM1aYw
@demiontongov4319
@demiontongov4319 6 ай бұрын
cool
@skillkrio
@skillkrio 10 ай бұрын
This Goat will unquestionably make me as a full stack development. Concise video packed with abundance of information. Thanks alot Dave
@misterl8129
@misterl8129 Жыл бұрын
Very good video. Also, we can use the eventEmitter without a class, just initialize the ee const {EventEmiter} = require('events') const myEvent = new EventEmitter();
@erichgq1
@erichgq1 7 ай бұрын
I know that you posted this video a while back but I am trying to lean more about node and web servers etc. and I will say this has been a pleasure to watch and try. I am 70 but I just enjoy dabbling in code. Your video is easy to follow and easy to understand. Thank you for taking the time to show us how to do things and make them work. Your folder missing is a perfect way to trap errors. Cheers
@BlueHat1
@BlueHat1 22 күн бұрын
What an incredible video! Thank you so much for explaining everything so well :)
@codewithkin
@codewithkin 8 ай бұрын
Thanks a lot for this Dave! Your courses are amazing, you are so underrated. I will share with everyone I know, and congratulations!
@ahmad-murery
@ahmad-murery 2 жыл бұрын
One cool feature about events is that you emit an event once but you can have multiple listeners on it, for example we can have two listeners listening on the "log" event, one of which is responsible for writing the data on the disk and the other is responsible for displaying it in the console, maybe later on we need a third one for sending emails (ex: to developer) when a specific data is logged (ex: uncaught errors/exceptions), the good part here is all of these logging implementations are independent of each others, so we can drop or modify any of them as needed without having to touch the code where the event is emitted. Thanks Dave,
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Spot on my friend! Great note 💯🙏
@ahmad-murery
@ahmad-murery 2 жыл бұрын
@@DaveGrayTeachesCode it's rather a humble note to a great content my friend 👍👌🚀
@caaltz
@caaltz 5 ай бұрын
I was on vacation and had to remember some stuff on node, thank God I found you
@kostiantynkarzhanov9216
@kostiantynkarzhanov9216 8 ай бұрын
Thank you so much! Very well explained! 💛
@imakshith
@imakshith 4 ай бұрын
Thanks a lot for this Dave! for sharing such an amazing content!
@tat-lyubch
@tat-lyubch 7 ай бұрын
Brilliant and simple as always. For people to take a first impression about subjects to involve. So we should be a good students. 😊
@danidan4565
@danidan4565 2 жыл бұрын
Thank you so much for this series. It really helped me a lot.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome! 🚀
@designcoded7585
@designcoded7585 2 жыл бұрын
nice refresher for us
@edwilsondasilva9946
@edwilsondasilva9946 Жыл бұрын
Excellent didactic. Clarity and objectivity. Thank you one more time. It has helped me in my work.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're welcome, and thank you for the kind words! 🙏
@codie12
@codie12 Жыл бұрын
Awesome tutorial for an absolute beginner to nodejs like me. Thx a lot!!!!!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Glad it was helpful!
@failasof44
@failasof44 Жыл бұрын
Dave man...you are my hero
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Happy to help!
@MrSalFav
@MrSalFav Жыл бұрын
Thank you, this is really good tutorial.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're welcome, Saleem! 🙏
@rangabharath4253
@rangabharath4253 2 жыл бұрын
Awesome series 👌😀
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad you think so! 💯
@computerscience1152
@computerscience1152 2 жыл бұрын
Love node, Awesome. also expecting for express tutorials
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you! 🙏 Yes, I'll be covering how to create Node.js only web server next and then the series will introduce Express to follow. 🚀
@leechiwaimichael7131
@leechiwaimichael7131 8 ай бұрын
watching you tutorial video pretty cool. On the other hand, wish to learn how to developing a payment gateway on the E-Commerce when I getting an online order to forward UPS and Federal Express
@sonamohialdin3376
@sonamohialdin3376 2 жыл бұрын
Awesome tutorial thank you
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad you liked it! 💯
@sonamohialdin3376
@sonamohialdin3376 2 жыл бұрын
@@DaveGrayTeachesCode Thank you
@ahmedelgaidi
@ahmedelgaidi Жыл бұрын
Really amazing
@TravinskiyVladislav
@TravinskiyVladislav Жыл бұрын
Its me. Again. and again thank you
@BennyThadikaran
@BennyThadikaran Жыл бұрын
Hi Dave, Whats the purpose of UUID in the error log? Isn't the datetime unique enough to serve as an identifier?. I am almost finishing this series and have learned so much from your tutorials. Thanks you so much!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Possibly. It all just depends on how you want to track the data. I'm giving one example. Overall, I'm showing concepts and you can apply them differently.
@Web-Himansu
@Web-Himansu Жыл бұрын
Sir best resource to learn nodejs and mongodb
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
My free course covers Node.js, Express.js and MongoDB: kzbin.info/www/bejne/nGOoonh5nrl1gpo
@alirezahekmati7632
@alirezahekmati7632 2 жыл бұрын
🚀
@haiderjaafer8164
@haiderjaafer8164 2 жыл бұрын
hi dave are you mean common core modules is existed or embbeded in node js previousely
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Yes, they are built-in to Node.js
@soniablanche5672
@soniablanche5672 2 жыл бұрын
it's actually console.error(), I tried console.err() in the past too lol.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Yes, 😂 I hope you saw my overlayed note in the video that offered the correction.
@keithbacalso9433
@keithbacalso9433 2 жыл бұрын
the ocnstant variable `EventEmitter` why is this not camel cased???
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
It is a class. Here is the docs link: nodejs.org/dist/latest-v16.x/docs/api/events.html#class-eventemitter
@jeetudewangan9836
@jeetudewangan9836 Жыл бұрын
what is the real use of EventEmitter ?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
It emits (aka releases or sends) events. Reference: nodejs.org/dist/latest-v18.x/docs/api/events.html#class-eventemitter
@jeetudewangan9836
@jeetudewangan9836 Жыл бұрын
@@DaveGrayTeachesCode thank you for reply
@itsmefrancois6825
@itsmefrancois6825 Жыл бұрын
Hi Dave, thanks for the video but I have to say that this was not helpful. You did use events but it wasnt clear why. Why using events when you can just call the exported function instead of calling emit? 95% of the video was puting together the log function instead of explaining events at all. I would have liked to get more in depth knownledge how events work and when to use them. Im my opinion you are totally missusing them.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
While I've helped many, I realize my teaching style isn't for everyone and I'm far from perfect. Keep going in this series, and you will see how I use an event in a practical way as we build a REST API.
@fardinahsan4319
@fardinahsan4319 10 ай бұрын
Why is the output like this? 31.07.2023 01:03:56 function v4(options, buf, offset) { if (_native.default.randomUUID && !buf && !options) { return _native.default.randomUUID(); } options = options || {}; const rnds = options.random || (options.rng || _rng.default)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` rnds[6] = rnds[6] & 0x0f | 0x40; rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided if (buf) { offset = offset || 0; for (let i = 0; i < 16; ++i) { buf[offset + i] = rnds[i]; } return buf; } return (0, _stringify.unsafeStringify)(rnds); } Log Event Emitted!
@fardinahsan4319
@fardinahsan4319 10 ай бұрын
index.js => const logEvents = require('./logEvents') const EventEmitter = require('events') class MyEmitter extends EventEmitter{ }; const myEmitter = new MyEmitter(); myEmitter.on('log',(msg)=>logEvents(msg)) // setTimeout(()=>{ //Emit Event myEmitter.emit('log','Log Event Emitted!') // },2000)
@fardinahsan4319
@fardinahsan4319 10 ай бұрын
logEvents.js => const {format} = require('date-fns') const {v4:uuid} = require('uuid') const fs = require('fs') const fsPromises = require('fs').promises const path = require('path') const logEvents = async (message)=>{ const dateTime = `${format(new Date(), 'dd.MM.yyyy\tHH:mm:ss')}` const logItem = `${dateTime}\t${uuid}\t${message} ` console.log(logItem) try{ if(!fs.existsSync(path.join(__dirname,'logs'))){ await fsPromises.mkdir(path.join(__dirname,'logs')) } //testing await fsPromises.appendFile(path.join(__dirname,'logs','EventLogs.txt'),logItem) } catch(err){ console.log(err) } } module.exports = logEvents
🍕Пиццерия FNAF в реальной жизни #shorts
00:41
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 75 МЛН
Универ. 13 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:07:11
Комедии 2023
Рет қаралды 4,6 МЛН
NPM Node Package Manager Modules | NPM Tutorial for Beginners
23:23
Events and Event Emitter in Node.js
7:01
Programming with Mosh
Рет қаралды 122 М.
Hardest Backend Node.js Concept to Master
11:20
Mehul - Codedamn
Рет қаралды 65 М.
PROOF JavaScript is a Multi-Threaded language
8:21
Beyond Fireship
Рет қаралды 263 М.
Intro to MongoDB and Mongoose | Node.js Tutorials for Beginners
17:06
How to use "Streams" to improve performance in Node.js?
12:22
Software Developer Diaries
Рет қаралды 18 М.
Node JS in Hindi #46 Events and  Event Emitter
10:05
Code Step By Step
Рет қаралды 42 М.
Build an API Proxy Server - Hide Your API Keys, Rate Limiting & Caching
32:20
ВЫ ЧЕ СДЕЛАЛИ С iOS 18?
22:40
Overtake lab
Рет қаралды 124 М.
Как работает автопилот на Lixiang L9 Max
0:34
Семен Ефимов
Рет қаралды 15 М.
WWDC 2024 - June 10 | Apple
1:43:37
Apple
Рет қаралды 10 МЛН
i love you subscriber ♥️ #iphone #iphonefold #shortvideo
0:14
Si pamerR
Рет қаралды 3,3 МЛН
Дени против умной колонки😁
0:40
Deni & Mani
Рет қаралды 12 МЛН