056
LVL 03 — MID DEVELOPER SESSION 056 DAY 56

NODE .JS

🎫 PIXELCRAFT-043
Feature | 🟠 Hard | Priority: 🔴 Critical

PixelCraft is client-only. Images disappear when you clear browser data. We need a server that stores images, user data, and settings. Start by understanding what a backend IS.
CONCEPTS.UNLOCKED
💚
What Node.js Is
JavaScript runtime outside the browser. Same language you know, running on servers instead of browsers. Powered by V8 — the same engine that runs Chrome.
Browser JS vs Node.js
Same language, different APIs. Browser: DOM, Canvas, fetch, localStorage. Node.js: fs (file system), http (server), path (file paths), os (system info). No window, no document.
📦
Built-in Modules
fs — read/write files. path — handle file paths. http — create servers. os — system information. No npm install needed — they come with Node.
Running JS from Terminal
node script.js — run any JavaScript file from the command line. No browser needed. The terminal is your new execution environment for backend code.
📜
npm Scripts
"dev": "node server.js" in package.json. Run npm run dev to start your server. Scripts standardize how the team runs, builds, and tests the project.
🌐
HTTP Server
A program that listens for requests and sends responses. Request: GET /api/health. Response: { status: 'ok' }. This is the foundation of every web backend.
HANDS-ON.TASKS
01
Run JavaScript from the Terminal
echo 'console.log("Hello from Node.js!")' > hello.js node hello.js // "Hello from Node.js!"
That's it. JavaScript running outside the browser. No HTML file, no <script> tag, no browser. Just the terminal.
02
Use Node.js Built-in Modules
const fs = require('fs'); const path = require('path'); const os = require('os'); console.log('Platform:', os.platform()); console.log('CPUs:', os.cpus().length); console.log('Free memory:', Math.round(os.freemem() / 1024 / 1024), 'MB'); // Read a file const content = fs.readFileSync( path.join(__dirname, 'hello.js'), 'utf-8' ); console.log('File content:', content);
In the browser, you can't read files from disk. In Node, you can read, write, delete, and create files. This is the superpower of server-side JS.
03
Create a Basic HTTP Server
const http = require('http'); const server = http.createServer((req, res) => { if (req.url === '/api/health' && req.method === 'GET') { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ status: 'ok', timestamp: new Date() })); } else { res.writeHead(404); res.end('Not Found'); } }); server.listen(3000, () => { console.log( 'Server running at http://localhost:3000' ); });
15 lines. A working HTTP server. Open http://localhost:3000/api/health in your browser — see the JSON response. You just built a web server.
04
Test in Browser

Open http://localhost:3000/api/health in browser — see JSON response. The browser is now the client and your terminal is the server.

05
Read PixelCraft's Backend Code

Identify the entry point, recognize familiar JS patterns. It's the same language — functions, objects, arrays, async/await — just with different APIs.

06
Close the Ticket
git switch -c feature/PIXELCRAFT-043-node-server git add server.js package.json git commit -m "Create basic Node.js HTTP server (PIXELCRAFT-043)" git push origin feature/PIXELCRAFT-043-node-server # PR → Review → Merge → Close ticket ✅
CS.DEEP-DIVE

Runtime environments.

The language stays the same, only the APIs change. Understanding this lets you learn any new environment quickly.

// Language vs Runtime:

JavaScript → browsers give you
              DOM, Canvas, fetch
JavaScript → Node.js gives you
              fs, http, path

// Same separation everywhere:

Java       → JVM (runtime)
Python     → CPython / PyPy
C#         → CLR (runtime)

// The language is defined by a spec
// (ECMAScript). The runtime provides
// the environment.
"Server Lab"
[A] Add 3 more routes to the raw HTTP server: /api/time (returns current time), /api/echo?msg=hello (echoes query params), / (returns a simple HTML page).
[B] Build a file-based notes system: POST /api/notes saves text to a .txt file (fs.writeFileSync), GET /api/notes reads it back. Data persists across restarts.
[C] Compare: list 10 APIs available in the browser but NOT in Node (e.g., document, window, localStorage) and 10 available in Node but NOT in the browser (e.g., fs, child_process, os).
REF.MATERIAL
ARTICLE
Node.js Foundation
Official intro: what Node is, how it works, the event loop, and why JavaScript on the server matters.
NODE.JSOFFICIALESSENTIAL
VIDEO
Fireship
Ultra-fast Node.js overview: V8 engine, event loop, non-blocking I/O, npm, and why it changed backend development.
NODE.JSQUICK
ARTICLE
Node.js Foundation
Complete fs module reference: readFile, writeFile, mkdir, readdir. The core of server-side file operations.
FSREFERENCEOFFICIAL
VIDEO
Programming with Mosh
Comprehensive Node.js tutorial: modules, built-in APIs, creating servers, and the fundamentals of backend development.
NODE.JSTUTORIAL
ARTICLE
Node.js Foundation
The built-in HTTP server: createServer, request/response objects, headers, status codes. The foundation before Express.
HTTPREFERENCEOFFICIAL
// LEAVE EXCITED BECAUSE
JavaScript runs servers! You created an HTTP server in 15 lines. The backend isn't mysterious — it's the same language with different tools.