For all intents and purposes, it's easiest to say I'm creating a CRM with a MySQL/NodeJS API on Firebase and a Client Side with VueJS. My API is nearly done and works perfectly with the dotenv environment variables but every time I deploy to Firebase, I hit a brick wall getting them to work.
Unfortunately all of the guides I've found on this seem to be specific to Angular or using outdated builds, etc. Even the Firebase documentation is driving me crazy.
Does anybody know of any resources that could help me to safely store and recall my database creds on Firebase the same way that I do locally with DotENV without having to use cloud functions? Or at least a guide that isn't specific to Angular, or anything really? I've been stuck on this for a week and it's thrown a huge wrench into my process. I can't get past this and it's very discouraging, especially just as I was picking up momentum.
Hi Bob!
We have an integration for Firebase at Doppler (https://doppler.com/) (*where I work).
I use it too for my side project Stock Alarm (https://www.indiehackers.com/product/stock-alarm) and it makes things a lot easier for me. Let me know if you already found a different solution otherwise I would be happy to help you get set up.
Cheers,
Ruud
Hey Bob!
Ran into this issue as well. Maybe I'm misunderstanding, but in order to access .env variables, you need to set them using 'firebase functions:config:set someservice.key="THE API KEY" '
HERE IS THE CONTEXT
I'm using a lot of pseudo code here because I don't want to fumble around the docs while I'm just trying to get a point across
Also... I'm sorry in advance. This is infuriating. I can't figure out what I'm doing to break my markdown here. my code runs. It's 100% the environment variable problem...
I apologize in advance, I finished typing this out and I realized how messy it is. I just don't know how to write it out much cleaner
MEVN Project split into Client and Server files inside of the root. The server doesn't actually use Vue, just Express. The Client side is Vue but it's not live yet so I'm not concerned with that.
In my development environment I have dotenv installed
I'm running:
localhost:9000 MEVN nodemon server with .env
server.js
This works just fine locally because .ENV works as expected
So, when I go to
localhost:9000/api/db/select/id/1
I get the JSON returned for ID 1 in my MySQL database's main table. The database layer works nicely.
localhost:5000 firebase live server
I go to
localhost:5000/api/db/select/id/1
I get the 404 error (obviously you can see why from the above code, the environment variables are only defined locally)
The thing is that I have tried making the same environment variables with firebase cloud functions and making an if statement:
server.js
// I'm going to put in some pseudo-code here for the sake of demonstration
// var is used instead of let so that it can be accessed globally here
I'm sure that isn't right but I was a lot more careful about syntax when I was going at it for hours. I've deleted a lot of the bad code to start fresh numerous times.
I've set the environment variables
Again, I'm going from memory, not looking at the documentation
firebase.functions:set db4.host="myHostIP", db4.user="myUsername" ...
Then I publish the functions:
firebase deploy --only functions
Finally, when I sign into firebase, there is nothing in FIREBASE > CLOUD FUNCTIONS > (Empty)
When I try to go to
localhost:5000/api/db/select/id/1
I still get the 404 error.@weekash sounds familiar?
Right , It's the same issue I was facing. Firstly .ENV variables are something that needs a true backend that can serve them . Locally you have NodeJS installed that can serve these variables ,so everything works fine. But when deployed we don't have any back-end at Firebase hence process.ENV is undefined there . I will consider this a limitation of Firebase. I was using React + Firebase , the firebase keys given to me were not sensitive so I dropped the idea of using .env variables .
What seem to be the problem exactly? Are you unable to start your Node app, or Vue frontend, or what exactly? Firebase on Node requires admin keys while Firebase credentials on the frontend can be ingested via env vars and processed in context by your build env.
If you’d like to provide us with more context I’m sure there’s a way to solve this.
I'm here to help! Firebase is The Devil.
I'm adding additional context as a main comment right now...