Files, processes and the network

This part of the JavaScript course leaves the language and talks to the machine: the file system comes first, reading and writing a file, paths built with node:path, a directory walked, and a stream piped from a source to a target. A program then starts another one, reads its environment and its arguments, and becomes a command-line tool with an exit status. The network is a server on node:http and a client built on fetch, with a config file validated before it is used. A worker thread takes work off the main thread, and the last two lessons hash with node:crypto and compress with node:zlib.

089 Reading files with fs.readFile fs.readFile with a callback and an encoding, fs.promises.readFile awaited, bytes against characters, and the ENOENT of a missing file Open 090 Writing files with fs.writeFile writeFile that truncates, appendFile, the flag option with wx and a, and a temporary folder made with mkdtemp and removed in a finally block Open 091 Paths with node:path join against string concatenation, resolve with a base, basename, dirname and extname, and the extension traps Open 092 Directories: listing, creating and walking readdir and the order it returns, mkdir with recursive, withFileTypes, and a walk that prints a tree Open 093 Streams: reading, writing and piping createReadStream and its chunks, pipeline to copy a file, readline as a line counter, and the ENOENT of a missing source Open 094 Child processes: execFile and spawn execFile with promisify, spawn with a stream and its close event, exit codes and signals, and the rejection of a failing call Open 095 process: environment, arguments and exit code process.env, process.argv from index two, process.cwd without printing it, and process.exitCode as the status of the run Open 096 A command-line tool a loop that parses flags and values, problems reported with the exit status, usage text, and the tool that writes notes into a temporary folder Open 097 An HTTP server with node:http createServer, listen on port 0, routes with status codes, reading a POST body, and closing the server before the program ends Open 098 An HTTP client with fetch status and headers of the answer, ok against a 404, response.json for a JSON body, and a POST that the server rejects with 400 Open 099 Reading and validating a config file readFile and JSON.parse, defaults merged with the spread, a schema check that reports a wrong type, and unknown keys with a suggestion Open 100 Worker threads a Worker started with eval code, the message event and a result, postMessage in both directions with terminate, the error event, and the exit code of a worker Open 101 Hashing with node:crypto createHash with sha256 and a hex digest, updating a hash from a stream, an HMAC with a key, and timingSafeEqual Open 102 Compression with node:zlib gzipSync and gunzipSync, gzip against deflate and brotli by size, a compressed file through a pipeline, and the Z_DATA_ERROR of a bad archive Open

Lessons