HostFn

hostfn env

Manage environment variables on the server.

The hostfn env command group manages environment variables stored on the remote server.

Subcommands

hostfn env list <environment>

Lists all environment variables on the server with values masked.

$ hostfn env list production

  ── Environment Variables ──
    DATABASE_URL=***
    JWT_SECRET=***
    REDIS_URL=***

  Total: 3 variable(s)

hostfn env set <environment> <key> <value>

Sets a single environment variable on the server. The .env file must already exist (use env push first).

hostfn env set production DATABASE_URL "postgresql://user:pass@host/db"

Key format requirements:

  • Uppercase letters, digits, and underscores only
  • Must start with a letter or underscore (e.g., DATABASE_URL, _SECRET)

hostfn env push <environment> <file>

Uploads a local .env file to the server. Creates a backup of the existing .env file before overwriting.

hostfn env push production .env.production

This command requires confirmation before executing.

hostfn env pull <environment> <file>

Downloads the .env file from the server to a local path.

hostfn env pull production .env.local

Warning: The downloaded file contains sensitive data. Do not commit it to git.

hostfn env validate <environment>

Validates that all required environment variables (defined in hostfn.config.json under env.required) are set on the server.

$ hostfn env validate production

  ── Validation Results ──
 DATABASE_URL
 JWT_SECRET
 STRIPE_KEY (missing)

  Missing 1 required variable(s)

  Set missing variables:
  $ hostfn env set production STRIPE_KEY "value"

Important Notes

  • Environment variables are stored in /var/www/{name}-{env}/.env on the server
  • After changing variables, you need to redeploy for changes to take effect (variables are read during deployment and injected into PM2 config)
  • The env push command creates a backup at .env.backup before overwriting