tezvyn:

⚙️Backend Dev

Backend engineering, APIs, and databases

1085 bites

More in Backend Dev — page 36

NODE_ENV: Flipping the 'Production' Switch
Node.js & Express2 min read

NODE_ENV: Flipping the 'Production' Switch

Setting NODE_ENV=production is like telling your Node.js app it's showtime, not rehearsal. This triggers performance optimizations in frameworks like Express, such as view caching and less verbose errors.

Sticky Sessions: Pinning a User to a Server
Node.js & Express2 min read

Sticky Sessions: Pinning a User to a Server

Sticky sessions pin a user's requests to a single server in a multi-server setup. This is crucial for stateful apps like Socket.IO, where a user's session lives on one machine.

Socket.IO Adapters: Scaling Beyond One Server
Node.js & Express2 min read

Socket.IO Adapters: Scaling Beyond One Server

Socket.IO adapters let you scale beyond one server. They use a backend like Redis Pub/Sub to broadcast messages across all your instances, so a user on Server A gets events from Server B. The footgun is assuming this handles everything; you still need a load.

Socket.IO Namespaces: Channels on One Connection
Node.js & Express2 min read

Socket.IO Namespaces: Channels on One Connection

Socket.IO namespaces are virtual channels over a single WebSocket connection, letting you split app logic without multiple connections. Use them for separate areas like `/admin` or for multi-tenancy.

Server-Sent Events (SSE): One-Way Data Push from Server
Node.js & Express2 min read

Server-Sent Events (SSE): One-Way Data Push from Server

Server-Sent Events (SSE) push data from server to client over one HTTP connection. It's a simpler, one-way alternative to WebSockets for things like live news feeds or status updates.

Node.js & Express2 min read

The 'ws' Library: WebSockets for Node.js Servers

The `ws` library is the standard for adding WebSocket servers to Node.js for real-time features like chat or live data feeds. It provides both server and client APIs for backend-to-backend communication.

Node.js & Express2 min read

Socket.IO Middleware: Your Connection Gatekeeper

Socket.IO middleware is a gatekeeper for new connections, running before a client is fully connected. It's ideal for authentication, rate limiting, or logging. The key footgun: you must always call `next()`, or the connection will hang until it times out.

Socket.IO Rooms: Broadcasting to Subsets of Clients
Node.js & Express2 min read

Socket.IO Rooms: Broadcasting to Subsets of Clients

Think of Socket.IO Rooms as server-side channels for grouping clients. They let you broadcast messages to a specific subset, like a private chat or users following a topic. Remember rooms are a server-only concept; a client can't see which rooms it has joined.

Socket.IO: Broadcasting Events to Clients
Node.js & Express2 min read

Socket.IO: Broadcasting Events to Clients

Broadcasting sends a server-side event to multiple clients at once, like a public announcement system. Use it for live notifications or game state updates. The footgun: by default, it only reaches clients on the same server; use an adapter for multi-server…

Node.js & Express2 min read

Socket.IO: Emitting and Handling Events

Socket.IO events are named messages sent between a client and server. One side `emit`s a message, the other listens with `on`. This powers real-time apps like chat. The footgun: don't `JSON.stringify` objects; Socket.IO does it for you.

Socket.IO: More Than Just WebSockets
Node.js & Express2 min read

Socket.IO: More Than Just WebSockets

Socket.IO is a library that guarantees real-time, bidirectional communication. It automatically picks the best transport—WebSocket or HTTP long-polling—to ensure your connection works. Use it for chat apps or live dashboards.

Polling vs. WebSockets: Stop Asking, Start Listening
Node.js & Express2 min read

Polling vs. WebSockets: Stop Asking, Start Listening

Polling is like repeatedly asking "Are we there yet?", while WebSockets is a persistent, two-way conversation. Use polling for infrequent updates, but use WebSockets for real-time apps like chat. The footgun is using polling for high-frequency updates.

Node.js & Express2 min read

V8's Garbage Collector: A Performance Pillar

V8's garbage collector is a key to its speed, using a "stop-the-world, generational, accurate" approach to reclaim memory. This runs automatically in Node.js and Chrome, but its pauses can impact performance.

SharedArrayBuffer: True Shared Memory for JS Threads
Node.js & Express2 min read

SharedArrayBuffer: True Shared Memory for JS Threads

SharedArrayBuffer is a shared whiteboard for JS threads, letting them access the same memory without slow data copies. It's used for high-performance parallel tasks. The footgun: without `Atomics` to coordinate, you'll get race conditions and corrupted data.

Node.js & Express2 min read

Node.js perf_hooks: A High-Precision Stopwatch for Your App

The `perf_hooks` module is a high-precision stopwatch for your Node.js code, offering nanosecond accuracy. Use it to benchmark async operations or HTTP request durations.

Node.js & Express2 min read

Backpressure: Don't Drown Your Node.js Streams

Backpressure is flow control for streams, preventing a fast producer from overwhelming a slow consumer, like a traffic light for data. It's crucial when piping a fast file read to a slow network write. Ignoring it causes data to buffer and crash your app.

Node.js & Express2 min read

Node.js Buffers: Handling Raw Binary Data

A Node.js Buffer is a fixed-size chunk of memory for raw binary data, like an array of bytes. Use it for file I/O or network streams where JS strings fail. The footgun is using `allocUnsafe()` without overwriting it, which can leak old, sensitive data.

Preventing Sensitive Data Exposure in Node.js
Node.js & Express2 min read

Preventing Sensitive Data Exposure in Node.js

Sensitive data exposure isn't just about database breaches; it's about accidentally leaking secrets. This happens when Node.js apps expose config files, API keys, or raw error messages, often by committing secrets to Git or failing to encrypt data.

HSTS: Forcing Future Connections to Use HTTPS
Node.js & Express2 min read

HSTS: Forcing Future Connections to Use HTTPS

HSTS is a response header that tells browsers to only use HTTPS for your site, automatically upgrading future HTTP requests. This prevents SSL stripping attacks.

Securing Cookies with HttpOnly, Secure, and SameSite
Node.js & Express2 min read

Securing Cookies with HttpOnly, Secure, and SameSite

Think of cookie attributes as security guards for your session data. They prevent common attacks by telling the browser strict rules for sending the cookie, mitigating risks like cross-site scripting (XSS) and cross-site request forgery (CSRF).