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

    Runtime and core tooling · Lesson 4 of 18

    process and command-line apps

    Read arguments and environment, set exit codes, and clean resources before exit.

    10 minutes2 games

    process represents the current program. process.argv contains command-line arguments, process.env carries string configuration, and process.cwd() is the working directory. Exit code zero means success; non-zero means failure—the contract between a CLI, shell and CI.

    shell arguments + env

    Node process

    stdout / stderr

    exit code

    Node.js
    function parseArgs(args) {
      const nameAt = args.indexOf("--name")
      return { name: nameAt >= 0 ? args[nameAt + 1] : "learner" }
    }
    const config = parseArgs(["--name", "Mona"])
    console.log("Hello " + config.name)
    console.log(process.env.APP_MODE || "development")

    Never print secrets from process.env. Validate configuration at startup and fail with a useful message. Instead of process.exit() during asynchronous work, set process.exitCode and let the event loop finish logs and cleanup.

    Important

    Every environment value is a string or undefined; Boolean(process.env.DEBUG) is true even for "false". Parse explicitly, choose safe defaults, and avoid secrets in arguments because process listings may expose them.

    Quick question

    A CLI fails validation. Appropriate exit code?

    Interview question

    How does process.cwd() differ from __dirname?

    Exercise

    Write getPort(env) returning numeric PORT or 3000, then print two cases.

    Expected output: 8080 3000

    Node.js
    function getPort(env) {
    
    }
    console.log(getPort({ PORT: "8080" }), getPort({}))

    Learn more from

    • Node.js: Processnodejs.org
    • The Twelve-Factor App: Config12factor.net

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    Previousnpm and package.jsonNextEvent loop: callbacks to async/await
    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.