tezvyn:

Node.js & Express

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

51 bites

Node.js & Express30 sec read

Promise.allSettled(): Never Fail a Batch of Promises

Promise.allSettled() waits for every promise in a set to finish, success or fail, without short-circuiting. Use it for independent tasks, like multiple API calls, where you need the outcome of each.

Node.js & Express30 sec read

Promise.race(): First Promise to Settle Wins

Promise.race() returns a promise that mirrors the outcome of the first promise in a set to finish—the winner takes all, whether it resolves or rejects. Use it to set a timeout on a network request.

Node.js & Express30 sec read

Promise.all(): Wait for Multiple Promises at Once

Promise.all() runs multiple promises in parallel, resolving only when all have succeeded. It's for when you need data from several API endpoints to render a single component.

Node.js & Express30 sec read

Async/Await: Write Non-Blocking Code That Reads Synchronously

async/await lets you write non-blocking code that reads like simple, synchronous logic. It's used for network requests or database queries without freezing your app. The biggest footgun is using `await` inside a function you forgot to declare as `async`.

Node.js & Express30 sec read

Promise .catch(): Handling Rejections

`.catch()` is the `try...catch` for promises, intercepting errors (rejections) in a chain. Use it at the end of a promise chain to handle failures from preceding steps, like a failed API call. The footgun: placing it mid-chain can swallow errors.

Node.js & Express30 sec read

Promise.then(): Each Call Returns a New Promise

Each `.then()` call returns a new promise, letting you chain async tasks sequentially. This is key for multi-step operations like API calls. The footgun is attaching multiple `.then()`s to the original promise, which executes them in parallel, not in sequence.

Node.js & Express30 sec read

JavaScript Promises: Handling Future Values

A Promise is an IOU for a future value from an async operation. Instead of blocking your code, you get an object that will eventually contain the result or an error. They're essential for API calls or file reads.

Node.js & Express30 sec read

Structuring Express Apps with Layered Architecture

Think of your Express app as a three-story building: a web layer for HTTP traffic, a service layer for business logic, and a data layer for your database. This keeps code organized and testable.

Node.js & Express32 sec read

Environment Variables: Config Outside Your Code

Think of a .env file as a Post-it note of secrets for your app, kept separate from your codebase. Use it for API keys or database URLs that change between environments. The biggest mistake is committing your .env file to Git, exposing all your secrets.

Node.js & Express30 sec read

package.json: The Blueprint for Your Node.js Project

The package.json file is the blueprint for a Node.js project, listing its dependencies and runnable scripts. It's essential for installing libraries (`npm install`) and running tasks (`npm test`).

Node.js & Express30 sec read

Libuv: The Engine Behind Node.js Async I/O

Libuv is the C library that powers Node.js's non-blocking I/O. It translates JavaScript's event loop into high-performance async calls for the host OS. The footgun is thinking this makes Node multi-threaded; it uses an event loop and a thread pool.