Node/Express Pocket Map
The Glovebox Reference
Section titled “The Glovebox Reference”Driving at 100mph doesn’t leave much time to read documentation. Keep this map in your glovebox.
Fig 1: Your Guide to the Node.js Galaxy (and Express).
Quick-Start Ignition
Section titled “Quick-Start Ignition”const express = require('express');const app = express();const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Driving on ${PORT}`));Routing & Traffic
Section titled “Routing & Traffic”| Method | Syntax | Use Case |
|---|---|---|
| GET | app.get('/path', handler) | Read/Retrieve |
| POST | app.post('/path', handler) | Create/Send |
| PUT | app.put('/path', handler) | Update (Replace) |
| DELETE | app.delete('/path', handler) | Destroy |
| Catch-All | app.all('*', handler) | 404/Dead Ends |
Accessing Data
Section titled “Accessing Data”- Route Params:
/users/:id->req.params.id - Query Strings:
/search?q=foo->req.query.q - Headers:
req.get('Content-Type')
Responses (The Cargo)
Section titled “Responses (The Cargo)”res.send("Text"): Quick text/HTML.res.json({ id: 1 }): API Data (Standard).res.sendFile("/abs/path/file.html"): Serve file.res.status(404): Set status code.
Middleware
Section titled “Middleware”// 1. Write itconst check = (req, res, next) => { if (ok) next(); else res.status(403).send('No');};
// 2. Use it (Global)app.use(check);
// 3. Use it (Route)app.get('/safe', check, handler);Extra Bits & Bytes
Section titled “Extra Bits & Bytes”📘 Intro to Express.js Study Guide (PDF)
Express.js Github Repo
Express All In One Lifeline App - Demo Repo