Configure Environment Variables

Environment variables allow you to configure application settings without hardcoding them into source files.

Create a .env file in the project root.

Add the following configuration:

Environment Variables

PORT

3000

NODE_ENV

development

Protect Environment Files

Never commit .env files containing secrets or credentials to a public repository. Add .env to .gitignore.

.env
PORT=3000
NODE_ENV=development

PORT defines the HTTP server port. NODE_ENV identifies the current application environment.

Key Takeaways
  • Environment variables separate configuration from source code.

  • The server port can be changed without modifying application code.

  • Sensitive configuration must not be committed to Git.