process.env.VAR is undefined despite the file being right there.
Wrong directory, wrong name, syntax errors, or platform substitution eating the value.
require('dotenv').config({ path: __dirname + '/.env' })API_KEY=abc123 # not export API_KEY=abc123env_file: - .env # versus ${VAR} resolved by compose itselfCOPY .env . # .dockerignore may exclude itFail fast at boot if required vars are missing.
NinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.
Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog