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

    Production: security, testing and deployment · Lesson 17 of 18

    API security fundamentals

    Prevent injection and configure CORS, rate limits and headers without false confidence.

    14 minutes2 games

    Security is layered: validation, per-resource authorization, parameterized queries, output encoding, TLS, dependency updates, sound secret handling, logging and monitoring. No single middleware makes an application secure. Begin with a threat model: who attacks, and what matters?

    Untrusted input

    Validate + authorize

    Parameterized data layer

    Rate limit + logs

    Safe response

    Node.js
    const allowedSort = new Set(["created_at", "title"])
    function safeSort(input) {
      return allowedSort.has(input) ? input : "created_at"
    }
    function corsOrigin(origin, allowed) {
      return allowed.includes(origin) ? origin : null
    }
    console.log(safeSort("title"), safeSort("title; DROP TABLE tasks"))
    console.log(corsOrigin("https://app.example", ["https://app.example"]) !== null)

    SQL values must use driver placeholders, never string concatenation. Column names often cannot be parameterized, so allowlist them. CORS is a browser policy, not authentication; non-browser clients ignore it. Rate-limit by identity or IP with correct proxy configuration and a deliberate burst policy.

    Important

    Never store or log passwords, tokens or payment data. Update Node and dependencies, run with least privilege, and limit body size, time and connections. On an incident, contain it, rotate credentials, review logs, fix the root cause and add regression coverage.

    Quick question

    Does CORS prevent curl from calling an API?

    Interview question

    How do you prevent SQL injection?

    Exercise

    Write allowRole(role) accepting only student and admin, otherwise guest. Print admin guest.

    Expected output: admin guest

    Node.js
    function allowRole(role) {
    
    }
    console.log(allowRole("admin"), allowRole("admin' OR 1=1"))

    Learn more from

    • OWASP: Node.js Securitycheatsheetseries.owasp.org
    • Node.js: Security best practicesnodejs.org

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousTesting with assert and node:testNextProject: tasks REST API and deployment
    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.