Environment variables
Configuring your application depending on the runtime environment
When building an application with Nokkio, you may need to configure it to behave differently in development and production. For example, if you use a third-party service, the URL you use to connect to that service might differ between environments. Nokkio supports environment variables for this purpose.
Setting environment variables
All Nokkio applications are created with a nokkio.env.json file where you can specify your environment variables for development and production. For example:
{
"development": {
"FOO": "BAR"
},
"production": {
"FOO": "BAZ"
}
}
Using environment variables
Once you have environment variables defined in nokkio.env.json, they are accessible via the NOKKIO_ENV global.
export default function IndexPage() {
return <div>The value is {NOKKIO_ENV.FOO}</div>;
}
In the above example, NOKKIO_ENV.FOO will return BAR in development and BAZ in your production build.
Using environment variables in server code
The same NOKKIO_ENV global is available in your server code, so your environment variables can be used in endpoints, gates, model events, and schedules:
export default function () {
return new Response(`The value is ${NOKKIO_ENV.FOO}`);
}