Home / Configs / Developer tools / .env file example

.env file example: database URL, port and secret key

Create a .env file for your app: port, database address and a secret key.

For any project that reads a .env file (Node, Python, PHP, Ruby). The variable names are examples, so rename them to match your app.

A .env file keeps settings and secrets out of your code. Fill in the values below to create one, then save it in your project folder and add it to .gitignore.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

Use false in production
Click Generate for a strong one
Used for sessions and tokens

.env
# myapp settings
APP_NAME=myapp
APP_ENV=development
APP_DEBUG=true
PORT=3000

DATABASE_URL=postgresql://app:change-me@localhost:5432/appdb

SECRET_KEY=replace-with-a-long-random-string

How this setup works

Diagram: .env file, then Your app, then Database
.env file (your values) → Your app (reads it at start) → Database (connects with the address)

Step-by-step setup

  1. Save the file as .env in your project folder, next to package.json or manage.py.
  2. Keep it out of Git: echo ".env" >> .gitignore.
  3. Load it: Node needs npm install dotenv, Python needs pip install python-dotenv. Laravel loads it for you.
  4. Make a copy without secrets named .env.example to share with your team.
  5. Restart your app. It should listen on port 3000.

What the important lines mean

Common errors and how to fix them

Variables are undefined
Your app only reads .env if you load it. Add dotenv or python-dotenv, and start the app from the folder that contains .env.
Database connection fails with a strange password error
Characters like @ : / # must be URL-encoded inside DATABASE_URL. The password field only allows safe characters for this reason.
Secrets ended up on GitHub
Add .env to .gitignore before your first commit. If it was already pushed, change every secret.

Frequently asked questions

Where do I put the .env file?
In the root folder of your project, next to package.json, manage.py or composer.json. Start your app from that folder.
Should I commit .env to Git?
No. Add .env to .gitignore and share a .env.example file with the secret values removed.
How do I load a .env file in Node or Python?
In Node, install dotenv and call require('dotenv').config(). In Python, install python-dotenv and call load_dotenv().

Written for: dotenv 16 (Node), python-dotenv 1.0, Laravel 11 · Updated 2026-10-02

Free tools that help

Fix a problem with this setup

More developer configs

See all 41 config generators