我有超过10个API帐户和密钥存储在 .env
.env
我的.env:
API_ACCOUNT_1="11111" API_SECRET_1="12121" API_ACCOUNT_2="22222" API_SECRET_2="232323" API_ACCOUNT_3="33333" API_SECRET_3="343434" API_ACCOUNT_4="44444" API_SECRET_4="454545" ...
我想实现但不想实现的目标:
import dotenv from "dotenv" dotenv.config() let accountInfo = [] for (let i = 1; i < 6; i++){ // it is not the correct syntax accountInfo.push([process.env.`'API_ACCOUNT_${i}'`, process.env.`'API_SECRET_${i}'`]) }
let accountInfo = [] for (let i = 1; i < 6; i++){ accountInfo.push([process.env[`API_ACCOUNT_${i}`], process.env[`API_SECRET_${i}`]]) }
请尝试