简体   繁体   中英

Js - get string variable from env file

I have this value in my env file:

REACT_APP_CHAIN_ID=56

and when I try to get the value of this variable in my file test.ts:

console.log("address : " + process.env.REACT_APP_CHAIN_ID);

I have undefined value?

Try with using typescript instead. Rename all your .js files into .ts . And use ts-node./index.ts instead.

But before that do not forget to install instances: npm install -g typescript ts-node or if you are using yarn: yarn add -DE typescript or just yarn add -D typescript then use npx tsc -init or simply tsc -init

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