tezvyn:

Node.js & Express

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

276 bites

More in Node.js & Express — page 14

Node.js & Express2 min read

ES Modules in Node.js: The Modern `import` System

ES Modules bring the browser's `import`/`export` syntax to Node.js, replacing the classic `require()`. Use ESM for modern projects to get features like top-level await. The main footgun is that you can't use `require()`, `__dirname`, or `__filename`.

npm Scripts: Your Project's Command-Line Shortcuts
Node.js & Express2 min read

npm Scripts: Your Project's Command-Line Shortcuts

Think of npm scripts as aliases for your project's common command-line tasks, stored in `package.json`. Use them to run build tools, start servers, or execute tests. The main footgun is forgetting `npm run` for custom scripts like `lint` or `build`.

Dependencies vs. DevDependencies: What's the Difference?
Node.js & Express2 min read

Dependencies vs. DevDependencies: What's the Difference?

Dependencies are packages your app needs to run in production (like a web framework). DevDependencies are for your development workflow (like a test runner). The footgun is mixing them up, which bloats your production build with unnecessary code.

package.json: The Blueprint for Your Node.js Project
Node.js & Express2 min 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 & Express2 min read

CommonJS: Node.js's Original Module System

CommonJS treats each file as a private box of code. You share tools using `exports` and import them with `require`. It's the original module system for Node.js, used to organize code into reusable pieces.

Node.js & Express2 min read

Node.js Cluster: Scaling on a Single Machine

The `cluster` module turns a single-threaded Node.js app into a multi-process server that uses all CPU cores. It's ideal for scaling network applications on one machine by sharing a single port.

Node.js & Express2 min read

Worker Threads: True Parallelism in Node.js

Worker threads give Node.js a separate brain for heavy lifting, letting you run CPU-intensive code without blocking the main event loop. Use them for tasks like image processing, not I/O. The footgun is assuming memory is shared; it isn't.

Libuv: The Engine Behind Node.js Async I/O
Node.js & Express2 min 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.

Node.js & Express2 min read

Node.js Child Processes: Escaping the Main Thread

A child process lets your Node.js app run external commands without blocking the event loop. Use it for CPU-intensive tasks like image processing or running system utilities. The footgun: using synchronous versions (`execSync`) will block your entire server.

Node.js & Express2 min read

Node.js Streams: Processing Data in Chunks, Not Blobs

Think of streams as a data conveyor belt, processing large files or network data in chunks instead of loading it all into memory. Use them for file I/O or network requests.

Node.js & Express2 min read

process.nextTick(): Cutting in Line on the Event Loop

process.nextTick() schedules a callback to run immediately after the current operation, before the event loop continues to timers or I/O. It's used for API consistency or error handling. The footgun is that overusing it can starve the event loop, blocking I/O.

JavaScript's Event Loop: Macrotasks & Microtasks
Node.js & Express2 min read

JavaScript's Event Loop: Macrotasks & Microtasks

The JavaScript event loop processes tasks like `setTimeout` callbacks or user clicks from a macrotask queue. A single, long-running macrotask blocks all rendering and user input, freezing the UI. The footgun is assuming `setTimeout(fn, 0)` runs instantly.

Node.js & Express2 min read

Event Loop vs Crypto Module

Node's crypto module offers both synchronous and asynchronous versions of CPU heavy operations like password hashing; the sync versions block the single threaded event loop, while async versions offload the work to a background thread pool.

Node.js & Express2 min read

The Node.js Event Loop: Concurrency on a Single Thread

The Node.js event loop lets a single thread handle high concurrency by offloading I/O. It's ideal for web servers and APIs, but the footgun is that any long-running synchronous code will block the entire application, freezing all other requests.

Node.js & Express2 min read

Node.js Events and the EventEmitter

Node.js handles concurrency with an event-driven model, not threads. "Emitters" fire named events that "listeners" react to, enabling non-blocking I/O for things like file reads and web requests.

Node.js & Express2 min read

V8: The Engine Powering Chrome and Node.js

V8 is the engine that runs your JavaScript, translating it into machine code. It powers both the Chrome browser and the Node.js server-side runtime. The common footgun is confusing the engine (V8) with the runtime environment that provides it with APIs.