.env · generator · Node.js

Node.js .env Generator

Every Node.js service starts with a .env file. This generator produces one for Express, Fastify, or Koa — with a Postgres connection string, a securely generated JWT secret, and a log-level knob.

.env for Node.js · 5 keys
Customize →
NODE_ENV=development
PORT=3000
DATABASE_URL=postgresql://user:password@localhost:5432/mydb
JWT_SECRET=Jo85Opx5TVlC-TViImGK_W60hG6Wk9EiaF80GdJX7BMCiLnx
LOG_LEVEL=info

Secrets regenerate on every page load. Want to combine stacks (e.g., Next.js + Stripe + Supabase)? Use the full generator.

How to use this .env in Node.js

  1. 1.Copy the .env into your project root.
  2. 2.Add .env and .env.local to .gitignore.
  3. 3.Install dotenv: npm install dotenv (or use Node 20+ --env-file=.env).
  4. 4.Import as the first line: import 'dotenv/config'.
  5. 5.Read anywhere: process.env.DATABASE_URL.

Gotchas

  • Don't call dotenv.config() after your DB connection code — env vars will be undefined.
  • Node 20+ has a built-in --env-file flag; you may not need the dotenv package at all.
  • Production hosts (Vercel, Railway, Fly) inject env vars via the dashboard — don't ship your .env.

Common keys explained

NODE_ENV

Runtime mode — development | production | test.

PORT

HTTP port the server binds to. Use 0 to let the OS pick in tests.

DATABASE_URL

Postgres/MySQL connection string.

JWT_SECRET

Secret used to sign access tokens. Always generate — never type.

LOG_LEVEL

One of trace | debug | info | warn | error. Default info.

Related tools

Other stacks