10 tips for running Node.js applications on OpenShift
Get the cheat sheet
- Don’t run as root.
- Use UBI containers.
- Try to use the most minimal image you can through two-stage builds.
- Don’t use npm start.
- Use health checks.
- Externalize secrets.
- Don’t use privileged ports.
- 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.