I'm using joi to structure data.
Now I'm unable to read environment variable set on startup.
I have a startup scrip.sh like:
PUBLIC_KEY="$(cat public_key.pem) docker-compose up --build"
Then I try to read that PUBLIC_KEY
variable.
const envVariables = joi.object({
PUBLIC_KEY: joi.string()
.default('PUBLIC_KEY')
})
I thought this would automatically identify the variable but it does not.
Is it possible to get the variable set on start up with Joi?
You can get environment variables using the process
core module. From the documentation :
The process core module of Node.js provides the env property which hosts all the environment variables that were set at the moment the process was started.
For example,
const pubKey = process.env.PUBLIC_KEY
process
if it's provided by CLI arguments or additionally use dotenv.config()
to read synchronously from .env
filesvar schema = {
a: Joi.string(),
b: Joi.string(),
c: Joi.string().when('a', { is: 'avalue', then: Joi.string().required() }).concat(Joi.string().when('b', { is: 'bvalue', then: Joi.string().required() }))
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.