Join our Newsletter — 33% off our NHI Course

What is the difference between using dotenv and a secrets manager for Node.js secrets?

dotenv loads variables from a local file into process.env, which is useful for non-sensitive development settings and older Node.js workflows. A secrets manager stores sensitive values centrally with encryption, access controls, rotation support, and auditability. The practical difference is whether you are just loading configuration or governing secret lifecycle and access.

Configuration loading is not secret governance

The key difference is not technical convenience alone. dotenv is a local mechanism for injecting values into a Node.js process, which makes it appropriate for developer-specific settings, test fixtures, and non-sensitive environment variables. A secrets manager, by contrast, is designed for sensitive material that needs lifecycle control: encryption at rest, access policy, rotation, audit trails, and revocation. For Node.js teams, that distinction matters because secrets are often copied into too many places when configuration and secret handling are treated as the same problem. That is where the operational risk begins. The NIST Cybersecurity Framework 2.0 is useful here because it frames secret handling as part of broader governance and protective control, not just application convenience. In practice, many teams discover the difference only after a `.env` file has already spread across laptops, CI jobs, and deployment artefacts.

How the two approaches behave in a Node.js application

With dotenv, the application reads a file at startup and places the contents into process.env. That is simple, fast, and convenient for local development, but it does not by itself solve confidentiality, rotation, access review, or evidence of who used a value and when. It also assumes the file is managed safely outside the application, which is often true in a small developer workflow and much less reliable once pipelines, containers, and shared infrastructure enter the picture.

A secrets manager changes the model. The application or deployment platform retrieves secrets from a central system with explicit permissions and, often, short-lived access. That lets teams separate configuration from sensitive material, rotate values without editing application files, and inspect access history when something looks wrong. For Node.js, the practical choice is usually about who should be able to read the secret, how often it changes, and whether the value must be traceable after deployment. Where the secret is tied to production access, API authentication, or privileged integrations, a secrets manager is the stronger control because it supports lifecycle management rather than simple loading.

  • Use dotenv for local developer convenience when the values are non-sensitive and low impact.
  • Use a secrets manager when the value is privileged, shared, rotated, or audited.
  • Keep the application interface the same, but change the storage and retrieval method behind it.
  • Verify that deployment and CI systems do not silently recreate the same secret sprawl you were trying to remove.

The guidance breaks down when teams treat the secret store as a dumping ground for every variable, because overcentralisation can create its own operational bottleneck.

Where the trade-off becomes visible in real projects

Tighter secret governance often increases setup and runtime complexity, so teams have to balance developer speed against control and accountability. The trade-off is usually acceptable for production secrets, but it can be excessive for harmless local settings such as port numbers, feature toggles, or mock endpoints. That is why the distinction should be made by sensitivity and lifecycle requirement, not by habit.

One common edge case is staging. Some teams leave staging on dotenv because it feels “non-production,” but staging often exercises real integrations and therefore carries real credentials. Another edge case is secret injection in containers or CI, where the file may never exist on disk, yet the same governance question still applies: who can retrieve the value, how is it rotated, and what evidence exists after access? The OWASP Non-Human Identity Top 10 is relevant when those secrets belong to services, build systems, or workload identities rather than humans, because the issue is then credential lifecycle and privilege scope rather than simple configuration loading. That said, there is no consensus that every environment variable should move into a vault-like system; the sensible boundary is whether the data needs security controls beyond local convenience.

Practitioner takeaway: Treat dotenv as a delivery mechanism for non-sensitive configuration, and treat a secrets manager as the control boundary for anything that must be protected, rotated, and audited.

Risk and Threat Considerations

The main risk in using dotenv for secrets is secret sprawl, where a sensitive value is duplicated into files, laptops, images, CI logs, and deployment artefacts. That increases the number of places an attacker or careless operator can expose or reuse the secret.

Failure mechanism: A file-based secret path depends on every copy being protected correctly, so one leak in source control, build output, container layers, or shared shell history can expose the same credential across environments. Without rotation and auditability, compromise is harder to detect and harder to contain.

Impact: An exposed Node.js secret can enable API abuse, service impersonation, data access, or lateral movement into connected systems, and the organisation may have no reliable way to prove where the value was used.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and CIS Controls v8 set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
NIST CSF 2.0 PR.AA-01 — Identity Management, Authentication and Access Control Secrets and access need governed authentication and access control.
GV.OC-01 — Organizational Context Secret handling should reflect production sensitivity and business impact.
Recommendation — Apply PR.AA-01 to restrict secret retrieval to authorised workloads and users. Use GV.OC-01 to classify which Node.js values require governed secret management.
CIS Controls v8 6.3 — Access Control Management Secret exposure is controlled by limiting who can read and use credentials.
3.3 — Data Protection Secrets require protection through storage and transmission controls.
Recommendation — Enforce CIS 6.3 to remove unnecessary access to Node.js secrets. Apply CIS 3.3 to protect sensitive Node.js secrets in storage and transit.
OWASP Non-Human Identity Top 10 NHI-01 — Secrets and Credential Management Node.js service secrets often govern non-human access and lifecycle control.
Recommendation — Manage Node.js service secrets with NHI-01 to rotate, scope, and revoke them reliably.

Practitioner Guidance

What to prioritise: Decide first which values are truly configuration and which values are credentials or privileged access tokens. That classification matters more than the storage format, because the wrong label leads teams to accept unsafe handling as “just environment variables.”

What to verify: Check whether the secret is ever committed, baked into an image, echoed in logs, or exported into shared CI output. If any of those happen, the problem is not just dotenv versus vaulting, but uncontrolled propagation.

Common mistake: Teams often keep dotenv in production for convenience and then add manual rotation steps later, which creates the worst of both worlds: hidden operational dependence without lifecycle control. The better pattern is to keep dotenv narrow and temporary, while production-sensitive values move to governed retrieval.

Practitioner takeaway: The right question is not which tool loads process.env more easily, but which approach gives you the evidence and control you will need when a secret must be revoked, rotated, or investigated.