Environment Variables
Every project generated by xpress-generator includes a .env file pre-filled with placeholder values for your chosen database. This page is the complete reference.
Common variablesβ
These are present in every generated project regardless of database.
| Variable | Default | Description |
|---|---|---|
PORT | 3000 | Port the server listens on |
NODE_ENV | development | Environment (development / production / test) |
JWT_SECRET | change-this | Secret key for signing access tokens |
JWT_EXPIRES_IN | 15m | Access token lifetime (e.g. 15m, 1h, 7d) |
REFRESH_TOKEN_SECRET | change-this | Secret for refresh tokens |
PORT=3000
NODE_ENV=development
JWT_SECRET=replace-with-a-long-random-string
JWT_EXPIRES_IN=15m
REFRESH_TOKEN_SECRET=replace-with-another-long-random-string
Security
Replace both secrets before deploying. Use at least 64 random bytes:
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
MongoDBβ
MONGO_URI=mongodb://localhost:27017/myapp
| Variable | Description |
|---|---|
MONGO_URI | Full MongoDB connection string |
For MongoDB Atlas:
MONGO_URI=mongodb+srv://<user>:<password>@cluster0.xxxxx.mongodb.net/myapp?retryWrites=true&w=majority
MySQLβ
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASS=yourpassword
DB_NAME=myapp
| Variable | Description |
|---|---|
DB_HOST | MySQL host |
DB_PORT | MySQL port (default: 3306) |
DB_USER | Database user |
DB_PASS | Database password |
DB_NAME | Database name |
PostgreSQLβ
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASS=yourpassword
DB_NAME=myapp
| Variable | Description |
|---|---|
DB_HOST | PostgreSQL host |
DB_PORT | PostgreSQL port (default: 5432) |
DB_USER | Database user |
DB_PASS | Database password |
DB_NAME | Database name |
SQL Serverβ
DB_SERVER=localhost
DB_PORT=1433
DB_USER=sa
DB_PASS=yourpassword
DB_NAME=myapp
| Variable | Description |
|---|---|
DB_SERVER | SQL Server hostname |
DB_PORT | SQL Server port (default: 1433) |
DB_USER | SQL Server user |
DB_PASS | SQL Server password |
DB_NAME | Database name |
NODE_ENV behaviorβ
The error handler middleware behaves differently based on NODE_ENV:
| Value | Stack trace in response | Unhandled error message |
|---|---|---|
development | β included | Full details |
production | β hidden | Generic "Something went wrong" |
test | β hidden | Generic message |
Set NODE_ENV=production in your deployment environment to avoid leaking stack traces.
.gitignoreβ
The generated .gitignore already includes .env:
node_modules/
.env
coverage/
dist/
tip
Create a .env.example file with placeholder values so other developers know what variables are needed β without exposing real secrets:
PORT=3000
NODE_ENV=development
JWT_SECRET=
JWT_EXPIRES_IN=15m
REFRESH_TOKEN_SECRET=
MONGO_URI=