Skip to content

Optimize Node.js ​

Measure application latency, memory and the event loop before increasing process counts or memory limits.

Measure before changing settings ​

Back up the site, choose a repeatable page or API request, and record load time, server response time, errors, memory and CPU use. Test while signed out and signed in. Change one thing at a time on staging before applying it to production.

Steps ​

  1. Use a supported Node.js release compatible with the application and install reproducible locked dependencies.
  2. Build in a controlled environment, then use the production start command and production mode. Remove development-only tooling from the runtime only after the build succeeds.
  3. Profile blocking synchronous I/O, expensive computation and slow database or external requests. Use streaming or background workers where suitable.
  4. Apply input size limits, request timeouts and bounded database pools. Do not solve slow dependencies by allowing unbounded concurrent requests.
  5. Cache safe public responses and scope private data correctly. Compress suitable responses at the serving layer without repeatedly compressing already compressed assets.
  6. Use a service supervisor, memory/CPU alerts and graceful restart. Add workers only after measuring available memory and database capacity.

Check the result ​

Repeat the same measurements and confirm login, forms, uploads and checkout still work. Keep the change only if it improves the measured problem without causing errors. Clear only the relevant cache and keep a rollback copy.

Last reviewed ​

2026-10-28