Node.js
- backend
- in current work
Node.js is what I reach for when I need a backend in JavaScript, which, given how much time I spend in the JS ecosystem, is often. It powers the server side of Free Clothes, runs the backend of the Meeting Intelligence Platform, and handles parts of LoS. The event-driven, non-blocking I/O model took a while to click, but once it did I started seeing why it works so well for things like real-time data and concurrent connections.
I usually pair it with Express for APIs because the combo is minimal and fast to set up. The npm ecosystem is both a blessing and a curse: there's a package for everything, but also five competing packages for everything, and half of them are abandoned. You learn to be picky. Node isn't my choice for CPU-heavy work, but for I/O-bound services and quick prototyping it's hard to beat.
/** Run `worker` over `items` with at most `concurrency` in flight; results keep input order. */
export async function mapLimit<T, R>(
items: T[],
concurrency: number,
worker: (item: T, index: number) => Promise<R>,
): Promise<R[]> {
const results = new Array<R>(items.length);
let next = 0;
const run = async () => {
while (next < items.length) {
const i = next++;
results[i] = await worker(items[i], i);
}
};
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, run));
return results;
}