Environment Variables
Configure build-time and runtime values for a NexHost service without committing them to source.
Environment Variables#
Use the service configuration screen to supply values that vary by environment, such as database connection strings, API credentials, and feature flags. Keep these values out of source archives and repositories.
Scopes#
Each variable can be available during one or both parts of a deployment:
| Scope | Use it when |
|---|---|
| Build | A build tool needs the value while generating the application output |
| Runtime | The running process needs the value after it starts |
| Both | The value is required during the build and by the running service |
Static-site values are incorporated into the built output. Change a build-time value and deploy again so a new artifact is produced. Runtime services receive their runtime configuration when they start; redeploy or restart the service after changing values that affect startup.
Set a value#
- Open the service settings in the dashboard.
- Add the key, value, and appropriate scope.
- Save the configuration.
- Start a deployment when the change needs a new build or runtime process.
Keep secrets server-side#
Do not use browser-exposed variables for credentials. Frontend frameworks may embed specially prefixed values into client-side bundles; check your framework’s documentation before putting any sensitive value in a build-time variable.
Runtime port#
Public Node services receive PORT from the runtime. Do not replace it with a hard-coded port; configure the application to listen on the provided value instead.