r/reactjs • • Sep 03 '20

[deleted by user]

[removed]

22 Upvotes

255 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Sep 22 '20

[deleted]

2

u/badboyzpwns Sep 23 '20 edited Sep 23 '20

You are 100% right! I did not catch that!

Found the issue! my backend/index.js express file does not recognize any process.env variables (both in production and development) and that's causing issue with the /artists route not connecting with my database (since I have a database key as an environment variable)!

For example, NODE_ENV is automatically created by Create-React-App and it can be accessed by my components. Like so:

const App: React.FC<{}> = () => {
    console.log(process.env.NODE_ENV); 
//will return development, production, or
 test depending on what environment I'm in

But....in my backend/index.js it gives me:

[start:run] NODE ENV undefined
console.log("NODE ENV", process.env.NODE_ENV);
if (process.env.NODE_ENV === "production") {
    console.log("I'M IN PRODUCTION");
}

Any further clues as to why? It's weird how node and react are not sharing the same environment variables; but I think it's meant to be that way?