Express

  • backend
  • in current work

Express is to Node.js what Flask is to Python: a thin layer that handles routes, middleware, and HTTP methods so I don't have to write raw server code. Every time I spin up a Node backend, Express is the first thing I install. It showed up in Free Clothes, and it runs the LoS server.

I know heavier frameworks exist (Nest.js, Adonis, and the like), but I keep coming back to Express because it stays out of my way. Define your routes, plug in the middleware you need, done. The lack of opinions means more decisions fall on you, which can be a downside on bigger teams, but for the way I work it's exactly the right amount of structure.

los/server/routes/desktop.tslines 72–94 · private repo
/** Server-sent events: the current name on connecting, then each new one. */
router.get('/theme/stream', async (req: Request, res: Response) => {
    let name: string | null;
    try {
        name = await readName();
    } catch (error) {
        console.error('Error reading the desktop theme:', error);
        return res.status(500).json({ error: 'Failed to read the desktop theme' });
    }
    res.writeHead(200, {
        'Content-Type': 'text/event-stream',
        'Cache-Control': 'no-cache, no-transform',
        Connection: 'keep-alive',
        'X-Accel-Buffering': 'no',
    });
    res.write(message(name));
    listeners.add(res);
    const heartbeat = setInterval(() => res.write(': still here\n\n'), HEARTBEAT_MS);
    req.on('close', () => {
        clearInterval(heartbeat);
        listeners.delete(res);
    });
});