Node Events Tutorial | Node.js Tutorials for Beginners

Поделиться
HTML-код
  • Опубликовано: 28 дек 2024

Комментарии • 57

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  3 года назад +14

    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: ruclips.net/p/PL0Zuz27SZ-6PFkIxaJ6Xx_X46avTM1aYw

  • @skillkrio
    @skillkrio Год назад +6

    This Goat will unquestionably make me as a full stack development. Concise video packed with abundance of information. Thanks alot Dave

  • @erichgq1
    @erichgq1 Год назад +1

    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

  • @misterl8129
    @misterl8129 Год назад +6

    Very good video. Also, we can use the eventEmitter without a class, just initialize the ee
    const {EventEmiter} = require('events')
    const myEvent = new EventEmitter();

  • @ahmad-murery
    @ahmad-murery 3 года назад +7

    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  3 года назад +3

      Spot on my friend! Great note 💯🙏

    • @ahmad-murery
      @ahmad-murery 3 года назад +1

      @@DaveGrayTeachesCode it's rather a humble note to a great content my friend 👍👌🚀

  • @caaltz
    @caaltz Год назад

    I was on vacation and had to remember some stuff on node, thank God I found you

  • @codewithkin
    @codewithkin Год назад

    Thanks a lot for this Dave! Your courses are amazing, you are so underrated. I will share with everyone I know, and congratulations!

  • @tat-lyubch
    @tat-lyubch Год назад

    Brilliant and simple as always. For people to take a first impression about subjects to involve. So we should be a good students. 😊

  • @kostiantynkarzhanov9216
    @kostiantynkarzhanov9216 Год назад +1

    Thank you so much! Very well explained! 💛

  • @imakshith
    @imakshith 10 месяцев назад

    Thanks a lot for this Dave! for sharing such an amazing content!

  • @danidan4565
    @danidan4565 3 года назад +3

    Thank you so much for this series. It really helped me a lot.

  • @codie12
    @codie12 Год назад

    Awesome tutorial for an absolute beginner to nodejs like me. Thx a lot!!!!!

  • @rangabharath4253
    @rangabharath4253 3 года назад +3

    Awesome series 👌😀

  • @noweare1
    @noweare1 22 дня назад

    Another awesome video, thanks

  • @failasof44
    @failasof44 2 года назад

    Dave man...you are my hero

  • @edwilsondasilva9946
    @edwilsondasilva9946 2 года назад

    Excellent didactic. Clarity and objectivity. Thank you one more time. It has helped me in my work.

  • @designcoded7585
    @designcoded7585 3 года назад +1

    nice refresher for us

  • @computerscience1152
    @computerscience1152 3 года назад +3

    Love node, Awesome. also expecting for express tutorials

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 года назад +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 Год назад

    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

  • @fardinahsan4319
    @fardinahsan4319 Год назад +1

    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 Год назад

      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 Год назад

      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

  • @MrSalFav
    @MrSalFav 2 года назад +1

    Thank you, this is really good tutorial.

  • @sonamohialdin3376
    @sonamohialdin3376 2 года назад +1

    Awesome tutorial 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.

  • @Yoshi-t5xKm
    @Yoshi-t5xKm 3 месяца назад

    i love this video

  • @haiderjaafer8164
    @haiderjaafer8164 3 года назад +1

    hi dave are you mean common core modules is existed or embbeded in node js previousely

  • @TravinskiyVladislav
    @TravinskiyVladislav 2 года назад

    Its me. Again. and again thank you

  • @ahmedelgaidi
    @ahmedelgaidi 2 года назад

    Really amazing

  • @Web-Himansu
    @Web-Himansu Год назад

    Sir best resource to learn nodejs and mongodb

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Год назад +1

      My free course covers Node.js, Express.js and MongoDB: ruclips.net/video/f2EqECiTBL8/видео.html

  • @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  Год назад +1

      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

  • @alirezahekmati7632
    @alirezahekmati7632 2 года назад +1

    🚀

  • @soniablanche5672
    @soniablanche5672 3 года назад +1

    it's actually console.error(), I tried console.err() in the past too lol.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 года назад +1

      Yes, 😂 I hope you saw my overlayed note in the video that offered the correction.

  • @itsmefrancois6825
    @itsmefrancois6825 2 года назад +2

    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  2 года назад +1

      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.