tezvyn:

Node.js & Express

Node.js, Express, Fastify, NestJS, Bun, Deno

276 bites

More in Node.js & Express — page 9

Node.js & Express2 min read

Environment-Specific Config: Beyond Hardcoded Values

Think of config as layered transparencies: a base file sets defaults, and environment-specific files (like `production.json`) override them. This keeps database hosts and feature flags tidy across dev, staging, and prod.

Node.js & Express2 min read

Optimize Node.js Images with Multi-Stage Builds

Multi-stage builds separate your build environment from your final runtime. This lets you use heavy tools to build your Node.js app, then ship only the lean production code, drastically reducing image size and attack surface.

PM2 Cluster Mode: Scale Node.js Across All Cores
Node.js & Express2 min read

PM2 Cluster Mode: Scale Node.js Across All Cores

PM2's cluster mode lets your Node.js app run on every CPU core, multiplying its capacity. It's essential for scaling networked apps on a single machine, but requires a stateless design—storing sessions in memory will break things as requests hit different…

Source-Concept Mismatch: Structured Logging
Node.js & Express2 min read

Source-Concept Mismatch: Structured Logging

Structured logging replaces free-text console.log output with consistently shaped JSON log lines carrying fields like timestamp, level, and request id, so aggregators can filter and correlate logs by machine, not by a human grepping text.

Node.js & Express2 min read

Creating a Basic Node.js Dockerfile

A Dockerfile is a recipe for building a portable image of your app. Use it to ensure your Node.js app runs identically everywhere, from your laptop to production.

PM2: The Process Manager for Production Node.js
Node.js & Express2 min read

PM2: The Process Manager for Production Node.js

PM2 is a process manager that keeps your Node.js apps online. Use it to automatically restart crashed apps, run them in the background, and scale across CPU cores. The footgun is forgetting to run `pm2 save` to make your process list survive server reboots.

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.