To define an array as an environment variable in Node.js, we can define it as a JSON array.
For instance, we write
ANY_LIST = ["A", "B", "C"]
to add the ANY_LIST
environment variable to our .env file.
Then we write
const LIST = JSON.parse(process.env.ANY_LIST);
to get the ANY_LIST
environment variable with process.env.ANY_LIST
.
And we parse it into an array with JSON.parse
.