📎 Webclip
Node.js Best Practices — Caching and REST
The page says Node apps should be written well to avoid problems later. It focuses on Redis caching for Express, server-wide monitoring and logging, the performance impact of NODE_ENV, and REST-aligned routes and HTTP methods.
Reading notes#
- Redis can be used to cache Express responses and speed up the app.
- The example installs Redis, changes its systemd setting, restarts the service, and adds the redis NPM module.
- A cache middleware checks Redis for an
id, returns cached data when it exists, and calls the database-backed handler when it does not. - Server or virtual machine monitoring and logging can help watch for issues from the app.
NODE_ENV=productionenables caching, so development should avoid it when fresh data is needed.- In production, Express caches views and does less Pug template work, which frees CPU for other tasks.
- The page shows how to set
NODE_ENVin Linux, macOS, Windows, and by prefixing the node command. - REST routes should match HTTP methods, with
POST,GET,PATCH, andDELETEused for article creation, listing, retrieval, updates, and removal. - When getting an item by ID, the ID should appear at the end of the route.
