Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    NODENode.js

    Runtime and core tooling

    • What is Node.js?
    • CommonJS and ES modules
    • npm and package.json
    • process and command-line apps

    Async I/O and events

    • Event loop: callbacks to async/await
    • Files and paths with fs/promises
    • EventEmitter
    • Streams and backpressure

    HTTP and APIs

    • Your first HTTP server
    • Routing and JSON bodies
    • Build a tiny router and middleware chain
    • REST: resources and status codes
    • Validation and error handling

    Production: security, testing and deployment

    • Authentication basics with crypto
    • Configuration and environment secrets
    • Testing with assert and node:test
    • API security fundamentals
    • Project: tasks REST API and deployment
    Node.js

    Async I/O and events · Lesson 5 of 18

    Event loop: callbacks to async/await

    Understand execution order and write asynchronous flow without callback hell.

    13 minutes2 games

    Node runs synchronous code on the call stack. When I/O starts, Node delegates it and keeps going. Once ready, its callback enters a queue and the event loop runs it when the stack is empty. Promise callbacks (microtasks) run before the next timer.

    Call stack

    Node/OS performs I/O

    Callback queues

    Event loop schedules callback

    Node.js
    console.log("A")
    setTimeout(() => console.log("D"), 0)
    Promise.resolve().then(() => console.log("C"))
    console.log("B")

    Callbacks came first; a Promise represents a future result and supports chaining, while async/await is clearer syntax over Promises. await pauses only its function, not the process. Start independent work together with Promise.all rather than awaiting it serially.

    Important

    Every Promise may reject. Use try/catch around await or attach .catch(), and never leave unhandled rejections. Do not place long CPU loops between callbacks; split or move them to a worker.

    Quick question

    Order of A/B/Promise/timer in the example?

    Interview question

    Concurrency versus parallelism in Node?

    Exercise

    Write loadBoth(a,b) awaiting both values with Promise.all and returning their sum, then print 7.

    Expected output: 7

    Node.js
    async function loadBoth(a, b) {
    
    }
    loadBoth(Promise.resolve(3), Promise.resolve(4)).then(console.log)

    Learn more from

    • Node.js: Event loopnodejs.org
    • MDN: async functiondeveloper.mozilla.org

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    Previousprocess and command-line appsNextFiles and paths with fs/promises
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.