Saltar al contenido principal

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.

VariableDefaultDescription
PORT3000Port the server listens on
NODE_ENVdevelopmentEnvironment (development / production / test)
JWT_SECRETchange-thisSecret key for signing access tokens
JWT_EXPIRES_IN15mAccess token lifetime (e.g. 15m, 1h, 7d)
REFRESH_TOKEN_SECRETchange-thisSecret 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
VariableDescription
MONGO_URIFull 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
VariableDescription
DB_HOSTMySQL host
DB_PORTMySQL port (default: 3306)
DB_USERDatabase user
DB_PASSDatabase password
DB_NAMEDatabase name

PostgreSQL

DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASS=yourpassword
DB_NAME=myapp
VariableDescription
DB_HOSTPostgreSQL host
DB_PORTPostgreSQL port (default: 5432)
DB_USERDatabase user
DB_PASSDatabase password
DB_NAMEDatabase name

SQL Server

DB_SERVER=localhost
DB_PORT=1433
DB_USER=sa
DB_PASS=yourpassword
DB_NAME=myapp
VariableDescription
DB_SERVERSQL Server hostname
DB_PORTSQL Server port (default: 1433)
DB_USERSQL Server user
DB_PASSSQL Server password
DB_NAMEDatabase name

NODE_ENV behavior

The error handler middleware behaves differently based on NODE_ENV:

ValueStack trace in responseUnhandled error message
development✓ includedFull details
production✗ hiddenGeneric "Something went wrong"
test✗ hiddenGeneric 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=