简体   繁体   中英

Environment variables not accessible within nodejs script file

I have written a shell script as below

export MONGO_DBNAME=dev-db
export MONGO_HOST=a.b.c.c.d:27017,w.x.y.z:27017
export MONGO_PORT=27017
export MONGO_USERNAME=devuser
export MONGO_PASSWORD=devpassword
export MONGO_REPLICASET=devreplicaset

babel-node email-report.js

the environment variables declared are not accessible within the node script using process.env

Can someone please help with why is this happening and how can it be resolved?

How are you accessing variable in your JS, its quite simple.

# ~ export DATA="HELLO"

#  ~ node
> process.env.DATA
'HELLO'

You can assign it like this also process.env.BAR = "bar"

To access in node console this process.env.BAR you will get your value "BAR"

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM