一个 .env 变量 returns 正确,但另一个在同一文件中未定义
One .env variable returns correctly but the other one is undefined in the same file
上下文:这是一个 React 应用程序,我想使用 .env 文件来存储我的数据库相关凭据。这在未来可能会改变,但由于某种原因我无法让它工作。
.env:
REACT_APP_FAUNA_API_KEY=**************** // returns fine if I console.log() it and I can also use it in the rest of the code
FAUNA_DB_ID=***************** // returns undefined
db.js:
import faunadb from "faunadb";
require("dotenv").config();
const client = new faunadb.Client({
secret: process.env.REACT_APP_FAUNA_API_KEY,
domain: "db.eu.fauna.com",
port: 443,
scheme: "https",
});
const q = faunadb.query;
console.log(process.env.FAUNA_DB_ID);
const databaseID = process.env.FAUNA_DB_ID;
export { client, q, databaseID };
对于 CRA 应用程序(根据 REACT_APP_FAUNA_API_KEY
变量进行猜测),只有以 REACT_APP_
开头的环境变量才会暴露给前端
https://create-react-app.dev/docs/adding-custom-environment-variables/
如果将变量重命名为 REACT_APP_FAUNA_DB_ID
,return 是否正确?
上下文:这是一个 React 应用程序,我想使用 .env 文件来存储我的数据库相关凭据。这在未来可能会改变,但由于某种原因我无法让它工作。
.env:
REACT_APP_FAUNA_API_KEY=**************** // returns fine if I console.log() it and I can also use it in the rest of the code
FAUNA_DB_ID=***************** // returns undefined
db.js:
import faunadb from "faunadb";
require("dotenv").config();
const client = new faunadb.Client({
secret: process.env.REACT_APP_FAUNA_API_KEY,
domain: "db.eu.fauna.com",
port: 443,
scheme: "https",
});
const q = faunadb.query;
console.log(process.env.FAUNA_DB_ID);
const databaseID = process.env.FAUNA_DB_ID;
export { client, q, databaseID };
对于 CRA 应用程序(根据 REACT_APP_FAUNA_API_KEY
变量进行猜测),只有以 REACT_APP_
https://create-react-app.dev/docs/adding-custom-environment-variables/
如果将变量重命名为 REACT_APP_FAUNA_DB_ID
,return 是否正确?