Skip to content

Modernize generated .gitignore to cover environment-specific dotenv files #381

Description

@Arynsingh

Description

The .gitignore generated by express-generator --git currently ignores .env, but does not ignore environment-specific dotenv files such as .env.local, .env.development, or .env.production.

For example, the current template contains:

# dotenv environment variables file
.env

I propose updating this to:

# dotenv environment variable files
.env
.env.*
!.env.example

This would help protect environment-specific configuration files that may contain credentials or other sensitive values, while still allowing projects to commit a safe .env.example file.

Why?

Node.js applications commonly use multiple dotenv files for different environments, for example:

  • .env
  • .env.local
  • .env.development
  • .env.production
  • .env.test

Ignoring only .env does not cover these additional .env.* files.

The proposed pattern follows a commonly used approach in modern Node.js project templates.

Proposed change

Update the JavaScript .gitignore template in:

templates/js/gitignore

from:

# dotenv environment variables file
.env

to:

# dotenv environment variable files
.env
.env.*
!.env.example

I would also be happy to add or update the relevant tests if this change is accepted.

Would this be a change the maintainers would be open to?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions