NodeJS Parseing RegEx from environmental variable


This Content is from Stack Overflow. Question asked by Damiisdandy

I am using the node package cors, and I’d like to pass regular expressions into the allowed origins. Still, since I am hosting my node application on multiple servers for “production” and “staging”, I am using environmental variables to store the origins. Still, when env variables are parsed they get returned as strings.

Here is an example of my env variable


this means I want only origins that have both “” and “” to work, according to so express documentation, so I parse the env variable as follows

export const CORS_ORIGINS = process.env.CORS_ORIGINS?.split(',')

but what is being set in the cors origins is ["/$/", "/$/"]
how do I make it this [/$/, /$/] instead.


Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?