Codux Help Center
Browse our articles to find the answers you need
Setting Environment Variables for Your Project
Environment variables play a crucial role in configuring and controlling the behavior of Node.js applications. These variables, such as tokens and flags, are accessible via the
process.env
object.To use the properties of
process.env
in your front-end application (for instance, in the browser), set the previewConfiguration.environmentVariables
key in your project's codux.config.json file. This configuration lets you append variables to the process.env
object to hold the user's environment data.previewConfiguration
- Description: Specifies environment variables to use globally across the project.
- Type: Object {}
- Properties:
environmentVariables
(Obj)
How to add to codux.config.json
Property: environmentVariables
The
environmentVariables
property is an object containing key value pairs of variables accessed from process.env
. 1 2 3 4 5 6 7 8 9 10 11
{ $schema": "https://wixplosives.github.io/codux-config-schema/codux.config.schema.json", ... "previewConfiguration": { "environmentVariables": { "SOCIAL_TWITTERX": "someValue1", "SOCIAL_INSTAGRAM": "someValue2", "SOCIAL_LINKEDIN": "someValue3" } } }
In your code, you can then access these values in the same way you would access any other environment variable, for example,
process.env.SOCIAL_TWITTERX
.Important!
The
NODE_ENV
key is special, and requires the value development
by Codux for rendering and editing components. Codux will override any other value that you might set for this key.Note:
Codux does not currently support automatically loading a
.env
file. Therefore, to get this working for your project, you'll need to provide the same values to your Codux config.If you need global variables to be consumed through the
window
object, you can use the global board setup field configuration as described here.Was this article helpful?