Files and Folders

Files and Folders: Reading and Writing Files, Paths and Folders, From Text to Data: Lines, CSV and JSON Files.

Updated

  1. Reading and Writing Files (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 (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 (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.