I am trying to use environment variables in a react app created on WSL. I cannot access the variables from my app.
Here is what I did:
Create a .env file at the root folder of my react app (within a client folder of a Rails app)
Create a variable: REACT_APP_API_URL=http://localhost:3000/api/v1/
Log the variable in my console: console.log(process.env.REACT_APP_API_URL)
Restarted the server
I keep getting an undefined variable.
Am I missing anything related to WSL maybe? I am a bit clueless as I cannot find a similar problem online.
Thank you!
I think your file is in the wrong directory. See here: Environment variables are always undefined in VueJs application (possible duplicate of your question).
Related
I am getting 500 internal server error after deploying a Next.js app to Vercel. The project works in the local machine but isn't working in the URL to which it is deployed to.
I have used environment variables in Vercel, which might be related to the issue.
I added these 4 env variables - NEXTAUTH_URL, NEXTAUTH_SECRET, TWITTER_CLIENT_ID, TWITTER_CLIENT_SECRET.
In my project, I've created a separate file '.env.local' which contains all of my project-related keys and URLs.
At first, this env variable 'NEXTAUTH_URL' was pointing to 'http://localhost:3000/'
NEXTAUTH_URL = http://localhost:3000/
And then, after deploying my app in Vercel, I updated that variable with the deployed URL in my project as well as in Vercel.
NEXTAUTH_URL = https://twitter-clone-seven-coral.vercel.app/
I have also added the above URL in 'Twitter's Developer Portal' in 'OAuth 2.0' in the 'Callback URI/Redirected URL' section:
Before deploying my app in Vercel, the CALLBACK URI/REDIRECT URL was pointing to https://localhost:3000/api/auth/callback/twitter
and WEBSITE URL was pointing to https://test.com
which I then updated after deploying the app initially.
This is the first time I'm working with Environment variables, so I do not have much idea on how to proceed with this error.
Package.json for reference:
Yes, have to set the Environment Variable , tried it with vercel but didnot supported or maybe missed something, but works fine with netlify, just deploy with the environment variable, from your project .env.local files, get the keys and values give also provide the NEXTAUTH_URL properly , then it should run
Had faced same problem and find out solution after a long research
The Trick is you have to set environment variable to vercel or any host platform
how to set environment variable in vercel
how to set environment variable in heroku
I have set some environment variables in the Netlify UI.
See here:
I am trying to use them in my code like this:
console.log("AUTH0_DOMAIN:");
console.log(process.env.AUTH0_DOMAIN);
console.log("AUTH0_CLIENT_ID:");
console.log(process.env.AUTH0_CLIENT_ID);
console.log("AUTH0_AUDIENCE:");
console.log(process.env.AUTH0_AUDIENCE);
When starting up the CLI local dev server using ntl dev it looks like the environment variables are injected:
But they all come through as undefined as shown here in the console:
So what am I doing wrong?
Why are they coming through as undefined?
P.S. I know I should not be using secret keys here because they will be exposed, but I still want to know how to do it for non-secret stuff.
UPDATE: The environment variables are also undefined after deploying live to Netlify. So it's broken on the live version and dev version.
UPDATE 2: Assigning it to a variable, as per below, also doesn't work:
const a_d = process.env.AUTH0_DOMAIN;
console.log(a_d); // This prints undefined
I am building a Vue app.
Turns out all Vue env variables need to be prefixed with VUE_APP_ inside the code and the Netlify UI.
So for example, it becomes const authDomain = process.env.VUE_APP_AUTH0_DOMAIN; in the code and you also have to use VUE_APP_AUTH0_DOMAIN in the Netlify UI.
This solved it for me:
netlify link
The netlify link command will link your local project to Netlify. See docs.
I did not think it was necessary to use netlify link because I already installed the Netlify CLI and was deploying my site automatically with GitHub but apparently it's needed.
I have an application running in Ruby on Rails. I use rbenv-vars to manage the environment variables used by the app and some of those variables are used in the environment config file to initialize AWS S3 storage setup in Paperclip's paperclip_defaults hash. However, recently I have updated the value of a S3-related variable in the .rbenv-vars file, restarted the application and Paperclip is always configured with the old (wrong) S3-related variable value. Oddly, the environment variable has the correct value (checked debugging the app and also using rails console) after Ruby environment startup. I temporarily fixed the issue by setting the variable AGAIN in ~/.bash_profile.
Has anyone ever experienced this? Any suggestions are welcome.
I suggest you to used Dot ENV GEM
By using the Gem you can define the ENV variables at system level.
If you are doing any changes related to configuration in rails application. You need to restart your application.
I experience an error : 'fetch': key not found: "APPLICATION_HOST" (KeyError)'
This errors occurres since I tried to implement a new gem that requires dotenv gem. That produced a lot of tries to fix. I revert my code to a stable one but I still cannot run my app supposed related to my machine configuration.
For now none of my environment variables in my .env file can be read by the app.
A teammate has the same code as mine and hasn't any config in his ~/.bashrc neither in ~/.bash_profileand our .env file has chown readable states.
Last information we use a gemset for this project.
Thanks by advance for any help
I solved the problem by cloning the repo in another folder and the project runs again!
I am using dokku-alot to deploy my Rails 4 app to my staging server and everything is working just swell.
One requirement I have with my current project is in regards to seed file data. I've had to keep my seeds.rb file out of version control because of sensitive information. However, I can't figure out how to add the seeds.rb file into the container after a build.
I've tried ssh root#myhost ap_name which gets me into the VM but even if I scp the files into there, the container doesn't see them. How can I drop a few files where my rails code is in the docker image?
Depending on how much information is in your seeds.rb file, you could use environmental variables. This the solution I ended up using.
You basically set the variable: config:set my-app SECRET=whateversupersecretinfo. Then in your code, you can extract that app variable by using ENV['SECRET']. (This works pretty much the same in Heroku) Not sure if that would solve your use case, but leaving this answer here for posterity.
subnote: In Node.js you can extract these variables like process.env.SECRET