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 15 of 18

    Configuration and environment secrets

    Separate configuration from code, validate it at startup, and keep secrets out of logs.

    10 minutes2 games

    The same code should run in development, staging and production; configuration changes: port, database URL and API keys. Keep it in the environment or a secret manager, not source. Parse and validate once at startup, then pass a typed object through the application.

    Secret manager / env

    Startup validation

    Typed config

    Application services

    Node.js
    function loadConfig(env) {
      const port = Number(env.PORT || 3000)
      if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("PORT must be valid")
      if (!env.APP_MODE) throw new Error("APP_MODE is required")
      return { port, mode: env.APP_MODE }
    }
    console.log(loadConfig({ PORT: "8080", APP_MODE: "test" }))

    Use defaults only for non-sensitive values. A missing secret should stop startup with the variable name but never its value. .env is for local development and belongs in .gitignore; production secrets come from encrypted platform settings or a vault with rotation and least privilege.

    Important

    Never print all of process.env, and never send a secret to the frontend; variables intentionally exposed to clients are public. When a secret leaks, remove it from logs and code and rotate it at the provider because deleting it from Git is insufficient.

    Quick question

    A production API key is missing. What should happen?

    Interview question

    Why are environment variables alone not a complete secrets strategy?

    Exercise

    Write parseBool(value) accepting only true and 1 as true, then print true false false.

    Expected output: true false false

    Node.js
    function parseBool(value) {
    
    }
    console.log(parseBool("true"), parseBool("false"), parseBool(undefined))

    Learn more from

    • The Twelve-Factor App: Config12factor.net
    • OWASP: Secrets Managementcheatsheetseries.owasp.org

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousAuthentication basics with cryptoNextTesting with assert and node:test
    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.