10 tips for nodejs cheat sheet cover

10 tips for running Node.js applications on OpenShift

Luke Holmquist


When you start running Node.js applications in containers, you should adopt some best practices that improve efficiency and security. This cheat sheet offers tips for making the most of Node.js JavaScript applications on Red Hat OpenShift as well as other container environments:

  1.  Don’t run as root.
  2.  Use UBI containers.
  3.  Try to use the most minimal image you can through two-stage builds.
  4.  Don’t use npm start.
  5.  Use health checks.
  6.  Logging.
  7.  Metrics.
  8.  Externalize secrets.
  9.  Don’t use privileged ports.
  10.  Set memory limits.



Node.js developers need to know how to do logging in a cloud-native environment. In container development, writing logs out to disk does not generally make sense because of the extra steps needed to make the logs available outside the container—and they will be lost once the container is stopped.

Logging to standard out (`stdout`) is more appropriate for the cloud, and structured logging (for example, using JSON) is the current trend. One excellent module is https://getpino.io/[pino], a fast, structured logger for Node.js that is easy to use.

Related Cheat sheets