Skip to content

Pocket Node-o-Dex

Neo-Retro Pocket Guide: Node-o-Dex

“Don’t lose this, kid. It’s the only thing standing between you and a stack trace.” — Professor Solo

Welcome to the Node-o-Dex. This is your “Hard Hat Required” quick reference for everything we’ve built so far. No fluff, just the specs.

One language, two very different job sites.

FeatureBrowser (The Sandbox)Node.js (The Construction Site)
RoleUI InteractivityBackend Logic & Systems
Global Objectwindow (The Glass Box)global (The Foreman)
DOM AccessYes (document.querySelector)NO (There is no HTML!)
File SystemRestricted (Security)Full Access (fs)

The essential CLI tools to start your engines.

CommandAction
node -vChecks your installed Node.js version. The “VIN number” of your engine.
node [file]Executes a JavaScript file (e.g., node app.js). Starts the machinery.
nodeEnters the REPL (Read-Eval-Print Loop). Your interactive testing workbench.

Variables that are always available on the job site. No import required.

  • global: The top-level scope (like window, but for the server).
  • __dirname: The absolute path to the directory the current file is in.
  • __filename: The absolute path to the current file itself.
  • process: The master control object. Environment variables, args, and exit codes.

Getting materials into the site at runtime.

  • process.argv: An array containing command line arguments.
    1. Path to Node executable.
    2. Path to current script.
    3. Your custom arguments (e.g., user).
Terminal window
node app.js --user=Solo
# process.argv[2] === "--user=Solo"

How we connect the pipes. Node’s legacy module system.

Exporting a Module (The Supply Line):

logger.js
const log = (msg) => console.log(msg);
module.exports = log; // Handing off the tool

Importing a Module (The Intake):

app.js
const logger = require('./logger'); // Grabbing the tool
logger('System Online');

Node.js is Non-Blocking. It doesn’t wait for heavy lifting (I/O) to finish before moving to the next task.

  • Blocking (Synchronous): The foreman waits for the cement to dry before laying bricks. (Bad for performance).
  • Non-Blocking (Asynchronous): The foreman pours cement, moves to lay bricks elsewhere, and comes back when it’s dry.

Quick reflexes for the command line operator.

  • Kill Process: Ctrl + C (The Emergency Stop Button).
  • Clear Screen: Ctrl + L or type clear (Sweeping the floor).

Standard issue gear. No installation required.

ModulePurpose
fsFile System: Read, write, and manage files.
pathPath Manipulation: Handle file paths safely across OSs (Mac/Windows).
osOperating System: Check specs (CPU, Memory, Uptime).
httpNetworking: Create servers and handle requests.

Reading the blueprints.

Reading a File (Async/Promises):

const fs = require('fs').promises; // Modern, Async
// Reading 'manifest.txt'
fs.readFile('./manifest.txt', 'utf-8')
.then((data) => console.log('Manifest:', data))
.catch((err) => console.error('Lost the paperwork:', err));

Spinning up a basic web server without any framework scaffolding.

const http = require('http');
// Blueprint for the server
const server = http.createServer((req, res) => {
if (req.url === '/') {
res.write('<h1>Job Site Open</h1>');
res.end();
}
});
// Open for business on port 3000
server.listen(3000);
console.log('Server running on port 3000...');

[!TIP] Solo’s Pro-Tip: “Put that ‘Live Server’ EXTENSION away for now and for node. We use node —watch app.js on this site. It restarts the server for us when we save files, but… we will still have to manually refresh the browser for front-end changes.


📘 Intro to Node.js Study Guide (PDF)