# Files and the Command Line

Command-line tools are where Node started: read a file, work something out, write the answer. Read and write files with fs/promises, build paths that work on Windows and macOS, turn CSV and JSON text into data, take arguments and settings, report errors with the right exit code, and see why Node can serve many people at once.

Updated: November 19, 2026

## [Files and Folders](https://www.ask-codey.com/courses/nodejs-in-depth/topics/node-files)

1. [Reading and Writing Files](https://www.ask-codey.com/lessons/node-files-read-and-write) (Apprentice): Node's fs/promises module reads a whole text file with readFile, saves one with writeFile, adds to one with appendFile, and reports a missing file with the error code ENOENT, which your code can catch and explain.
2. [Paths and Folders](https://www.ask-codey.com/lessons/node-files-paths-and-folders) (Apprentice): A relative path starts from the terminal's folder, not the script's, so a Node program finds its own files with path.join and import.meta.dirname, and lists and makes folders with readdir and mkdir.
3. [From Text to Data: Lines, CSV and JSON Files](https://www.ask-codey.com/lessons/node-files-text-to-data) (Apprentice): A file arrives as one long string, so a Node program splits CSV text into lines and fields, turns numbers from text into numbers, skips blank lines and reports bad rows, and reads and writes JSON files with JSON.parse and JSON.stringify.

## [The Command Line](https://www.ask-codey.com/courses/nodejs-in-depth/topics/node-command-line)

1. [Arguments, Exit Codes and Clear Errors](https://www.ask-codey.com/lessons/node-command-line-arguments) (Apprentice): A command-line tool reads the words typed after it with process.argv and util.parseArgs, prints a --help line, sends errors to console.error with a message a person can act on, and sets process.exitCode so the computer that ran it knows whether it worked.
2. [Settings from Environment Variables](https://www.ask-codey.com/lessons/node-environment-variables) (Apprentice): A setting that changes from one computer to another, such as where a data folder is, belongs in an environment variable, which a Node program reads from process.env with a default from ??, and which comes from the terminal or from an .env file loaded with node --env-file.

## [How Node.js Waits](https://www.ask-codey.com/courses/nodejs-in-depth/topics/node-how-node-waits)

1. [The Event Loop, in Server Terms](https://www.ask-codey.com/lessons/node-event-loop-in-server-terms) (Journeyman): Node runs your JavaScript on one thread, like one waiter serving many tables, so it serves many requests at once by starting slow file and network work and moving on while it waits, and a long CPU-heavy loop makes every user wait.

## [Exercise: Training Log](https://www.ask-codey.com/courses/nodejs-in-depth/topics/exercise-node-training-log)

1. [Exercise: Training Log](https://www.ask-codey.com/lessons/exercise-node-training-log) (Apprentice): Build the running club's training-log command, which reads a CSV file, prints one runner's week, saves it as JSON when asked, takes its data folder from an environment variable, and reports a missing file or an unknown runner with a clear message and exit code 1, while tests run it as its own program.

## [Up Next: Building Web APIs](https://www.ask-codey.com/courses/nodejs-in-depth/topics/node-up-next-web-apis)

1. [Up Next: Building Web APIs](https://www.ask-codey.com/lessons/node-up-next-web-apis) (Novice): Module 1 gave you Node's toolkit (running and debugging programs, modules and npm, files, arguments, settings and the event loop); this lesson shows which tool fits which job, the Expense Tracker CLI project that uses them all, and how Module 2 turns your code into a server.

Source: https://www.ask-codey.com/courses/nodejs-in-depth/chapters/node-files-and-the-command-line
