| Level Navigation: 1 | 2 | 3 | (4ℹ️) | (5ℹ️) | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14⚡ | 15⚡ | (16ℹ️) | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26⚡ | 27⚡ | 28⚡ | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39⚡ | 40⚡ |
The next series of levels introduces working with data through the classic CRUD (Create, Read, Update, Delete) operations. These levels break the CRUD flow into small, repeatable steps that build on each other, allowing you to iterate confidently. Instead of starting with a full SQL database like Supabase’s Postgres, these levels use simple in-memory arrays (declared as module-level globals) so you can focus on understanding route behavior and data manipulation patterns without the complexity of database connections and persistence concerns.
When learning to build APIs, it’s common to start with in-memory storage before introducing database complexity. This approach allows you to:
What is a module-level global?
In Node.js, when you declare a variable at the top level of a file (outside of any function), it becomes a module-level variable. This variable is shared across all code within that module (file), and any route handler in that file can access and modify it.
Example:
// src/index.js
import express from 'express';
const app = express();
// This is a module-level global array
// It's declared outside any function, at the "top level" of the module
const items = [
{name: "gum", brand: "Bubalishous"},
{name: "toothpaste", brand: "Colgate"},
{name: "bike", brand: "Huffy"}
];
app.get('/items', (req, res) => {
// Route handlers can access the items array
res.json(items);
});
app.post('/items', (req, res) => {
// Route handlers can modify the items array
items.push(req.body);
res.status(201).json(req.body);
});
Why use module-level globals for in-memory data?
Important limitations to understand:
What comes next:
The upcoming levels will cover how to:
Think of in-memory arrays as a training ground—once you understand how to manipulate data with arrays, moving to a database is mostly about learning the syntax, not the concepts.