Skip to content
tezvyn:

All bites

The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.

8667 bites

Page 293

API Versioning: Managing Change Without Breaking Clients
Node.js & Express2 min read

API Versioning: Managing Change Without Breaking Clients

API versioning lets you evolve an API without breaking existing clients. It's essential for public APIs or services with multiple frontends that can't update in lockstep. The footgun is delaying versioning, forcing a painful migration on early users.

Mongoose: Schemas are Blueprints, Models are Factories
Node.js & Express2 min read

Mongoose: Schemas are Blueprints, Models are Factories

A Mongoose Schema is the blueprint for your data, defining its shape and types. A Model is the factory that uses this blueprint to create, query, and save documents in MongoDB. The common footgun is trying to query the blueprint instead of the factory.

HTTP Status Codes: The Server's Signal
Node.js & Express2 min read

HTTP Status Codes: The Server's Signal

HTTP status codes are the server's signal for a request's outcome: success, client error, or server error. You see them when fetching data (200 OK), hitting a bad link (404), or when a server fails (500). Footgun: Don't just check for 'not 200'.

Node.js & Express2 min read

REST: The Architectural Style of the Web

REST is a set of design rules, not a strict protocol, for building massive distributed systems like the web. These constraints enable independent component deployment, scalable interactions, and a layered architecture that supports caching and security.

cookie-parser: From Header String to Usable Object
Node.js & Express2 min read

cookie-parser: From Header String to Usable Object

The cookie-parser middleware translates the raw Cookie header string into a usable req.cookies object. It's used in Express apps to read session IDs or user preferences.

Morgan: One-Line Request Logging for Express
Node.js & Express2 min read

Morgan: One-Line Request Logging for Express

Morgan is a plug-and-play stenographer for your Express app, automatically logging every incoming HTTP request. Use its predefined formats for quick debugging or create custom formats for production access logs.

Node.js & Express2 min read

Helmet.js: Secure Express Apps with HTTP Headers

Helmet.js adds a security layer to Express apps by setting crucial HTTP headers. Use it in any public-facing Node app to prevent common attacks like XSS. The footgun: its default Content-Security-Policy is strict and requires app-specific configuration.

CORS Middleware: Unlocking Cross-Origin Requests in Express
Node.js & Express2 min read

CORS Middleware: Unlocking Cross-Origin Requests in Express

The cors middleware tells browsers which external websites can read your Express API's responses. Use it when a frontend on one domain needs to fetch data from your API on another.

Express Middleware: Intercepting Requests Before Your Route Handler
Node.js & Express2 min read

Express Middleware: Intercepting Requests Before Your Route Handler

Express middleware is like a bouncer for your routes, running code before your main handler. Use it for logging, authentication, or parsing request bodies. The biggest footgun is forgetting to call next() or send a response, which leaves requests hanging.

Express Error Middleware: Your App's Safety Net
Node.js & Express2 min read

Express Error Middleware: Your App's Safety Net

Express error middleware is a safety net that intercepts unhandled errors, preventing crashes. It's used to centralize logging and format consistent error responses. The biggest footgun is placement: it must be defined *after* all other routes and middleware.

Scaffold an Express App with `express-generator`
Node.js & Express2 min read

Scaffold an Express App with `express-generator`

The express-generator CLI is a blueprint for new Express apps, instantly creating a standard folder structure and boilerplate files. Use it to skip tedious setup of routes and views.

express.Router: Group Routes into Modular Files
Node.js & Express2 min read

express.Router: Group Routes into Modular Files

express.Router is a mini-app for your routes. It lets you group related endpoints (e.g., all /users/... routes) into their own file, keeping your main app.js clean. The footgun is forgetting to mount the router in the main app with app.use().

Express Middleware: The Chain of Command for Requests
Node.js & Express2 min read

Express Middleware: The Chain of Command for Requests

Express middleware is a chain of functions a request passes through. Each function can inspect, modify, or stop the request, useful for logging, auth, or body parsing.

Express Request and Response Objects (req, res)
Node.js & Express2 min read

Express Request and Response Objects (req, res)

Think of Express's req and res as an incoming letter and your reply. req contains the client's request details, like headers and data, while res is your toolkit for sending a response. They are the core of every route handler.

Express.js: Basic Request Routing
Node.js & Express2 min read

Express.js: Basic Request Routing

Express routing connects a request's path and HTTP method (like GET /) to a specific handler function. This is the core of any Express app, used to define API endpoints or handle form submissions. A common mistake is using the wrong method for a request.

Creating Your First Express Server
Node.js & Express2 min read

Creating Your First Express Server

Think of an Express app as three steps: require the library, create an instance, and listen on a port. This is the foundation for any Express-based API or web server.

Node.js & Express2 min read

Node's zlib Module: Trading CPU for Bandwidth

Node's zlib module trades CPU cycles for network bandwidth by shrinking data with algorithms like Gzip and Brotli. Use it to compress large API responses or files before sending them. The main footgun: never use synchronous ...Sync methods in a server.

Node.js & Express2 min read

Hashing Data with Node.js's `crypto` Module

Hashing creates a unique, fixed-size fingerprint of data. It's a one-way process used to verify data integrity or store passwords securely without saving the plain text. The footgun is using weak algorithms like MD5 or SHA1 for security-sensitive tasks.

Node.js & Express2 min read

WHATWG URL API: Safely Parse URLs, Not Strings

Treat URLs as structured objects, not messy strings. The WHATWG URL API parses a URL into components like protocol and path, just like JSON.parse. Use it for incoming requests or outgoing API calls. The footgun is using the legacy url.parse().

Node.js & Express2 min read

path.join() vs. path.resolve(): Concatenation vs. Calculation

path.join() glues path segments together, while path.resolve() calculates an absolute path. Think string building vs. cd commands. Use join for relative paths and resolve for absolute ones.