Search code examples
javascriptreactjsenvironment-variablessupabasesupabase-database

Why is my env variable showing up as undefined?


I'm trying to get data from a table with Supabase. When I try store the URL and the Key on a .env file it comes back as undefined.

File: App.js

import React, { useEffect } from "react";
import ButtonsSection from "./ButtonsSection";
import Header from "./Header";
import InputsSection from "./InputsSection";
import ResultsSection from "./ResultsSection";

export default function App() {
  useEffect(() => {
    console.log(process.env.REACT_APP_SUPABASE_URL);
  }, []);

  return (
    <div>
      <Header />
      <InputsSection />
      <ButtonsSection />
      <ResultsSection />
    </div>
  );
}

File: Database.env

REACT_APP_SUPABASE_URL='https://**********.supabase.co'
REACT_APP_SUPABASE_ANON_KEY='***************.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF2bW56a2xka25hZG1wcmZtc3JqIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTU0MDQ4NDQsImV4cCI6MTk3MDk4MDg0NH0.Th_x*******************************'

Solution

  • assuming you are using create-react-app. File name should be ".env" not "Database.env" and it should be in the root folder of the project.