2021-04-01
1369
#node
Adewale Abati
4148
Apr 1, 2021 â‹… 4 min read

Handling and dispatching events with Node.js

Adewale Abati Web engineer, tech lifestyle YouTuber, public speaker. Building communities and open source for the Next Billion Users.

Recent posts:

TypeScript logo over a pink and white background.

Drizzle vs. Prisma: Which ORM is best for your project?

Compare Prisma and Drizzle ORMs to learn their differences, strengths, and weaknesses for data access and migrations.

Temitope Oyedele
Nov 21, 2024 â‹… 10 min read
Practical Implementation Of The Rule Of Least Power For Developers

Practical implementation of the Rule of Least Power for developers

It’s easy for devs to default to JavaScript to fix every problem. Let’s use the RoLP to find simpler alternatives with HTML and CSS.

Timonwa Akintokun
Nov 21, 2024 â‹… 8 min read
Rust logo over black marble background.

Handling memory leaks in Rust

Learn how to manage memory leaks in Rust, avoid unsafe behavior, and use tools like weak references to ensure efficient programs.

Ukeje Goodness
Nov 20, 2024 â‹… 4 min read
Robot pretending to be a person.

Using curl-impersonate in Node.js to avoid blocks

Bypass anti-bot measures in Node.js with curl-impersonate. Learn how it mimics browsers to overcome bot detection for web scraping.

Antonello Zanini
Nov 20, 2024 â‹… 13 min read
View all posts

3 Replies to "Handling and dispatching events with Node.js"

  1. Hello!
    in your example:

    myEmitter.on(‘ping’, function (data) {
    console.log(‘First event: ‘ + data);
    });

    myEmitter.emit(‘ping’, ‘My first Node.js event has been triggered.’);

    What’s the difference of doing:

    function ping(data){
    console.log(“First Event: ” + data)
    }
    ping(‘My first Node.js event has been triggered.’)

  2. The difference in the two scenarios you listed is when you use Events your functions are fired in response to an event while simply calling a function means the functions are fired almost immediately.

  3. The difference is that anytime that event is triggered asynchronously, the event handler prints out the data sent to it. The event handler can do anything like send new signup email or subscription reminder emails. The event can be triggered multiple times as long as the app is running.

Leave a Reply