Node.js Event Handling

Node.js Event
Handling
Hans Yip
Format of Node.js API/function call
API_function("data_here", callback_function_name(var_data));
Callback_function_name(var_data) {
 
// function content
}
OR (No name function)
API_function("data_here", (var_data) => {
 
// function content
});
Examples of Event
Examples of event: phone_ring, door_bell_ring
We need to create event handler (function/program) to take care of the
event:
phone_ring_handler () {
 
Pick up the phone;
 
Ask the person’s name;
 
Write down the message;
 
Hang up the phone;
 
Return message;
}
Examples of Event
Start the event:
when phone_ring (phone_ring_handler(), callback_function1(msg));
Define callback function:
callback_function1(msg) {
 
send “msg” to hans;
 
exit;
}
Note: 
You can re-write callback_function1 to be a no-name function.
Slide Note
Embed
Share

Explore Node.js event handling with examples of creating event handlers, defining callback functions, and starting events like phone ringing. Learn how to effectively manage events in Node.js programming.

  • Node.js
  • Event handling
  • Callback functions
  • Programming

Uploaded on Feb 22, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Node.js Event Handling Hans Yip

  2. Format of Node.js API/function call API_function("data_here", callback_function_name(var_data)); Callback_function_name(var_data) { // function content } OR (No name function) API_function("data_here", (var_data) => { // function content });

  3. Examples of Event Examples of event: phone_ring, door_bell_ring We need to create event handler (function/program) to take care of the event: phone_ring_handler () { Pick up the phone; Ask the person s name; Write down the message; Hang up the phone; Return message; }

  4. Examples of Event Start the event: when phone_ring (phone_ring_handler(), callback_function1(msg)); Define callback function: callback_function1(msg) { send msg to hans; exit; } Note: You can re-write callback_function1 to be a no-name function.

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#