Problem in calls url in my fronn end.
I have a problem when i try to send method post on login in my applicatiion. In console the webbrowser when i send method post, i receive a error of axios.post "parent: Error: connect ECONNREFUSED 127.0.2.1:3306". In my database i has sucess in seeds aplicated. Other stranger thing is when i send method post my app make too other send method get. Can i help me ?
35 Replies
Project ID:
a297026f-2372-413d-8aa5-0af4cc4fe8bb
did you mean to use
127.0.0.1
instead?a297026f-2372-413d-8aa5-0af4cc4fe8bb
Hi Luna. No, my app is sending to 127.0.2.1:3306
1. Why?
2. Are you trying to connect to the local host?
3. Shouldnt you be using env.DATABASE_URL ?
š¤
On my backend i have this log.
You're connecting to mysql correct? Are you using a hosted db or one via services in railway?
If you're using the mysql service I'd highly suggest reading https://docs.railway.app/databases/mysql
Yes my database stay in here
You likely need to use the envs provided by railway.
connecting to localhost isnt going to do anything in this case.
Okay Luna. Im see this link
My database there is this varaibles. See
yes... now you need to use that in your code.
those are all environment variables that're set
config .json ?
no.. in your code.
instead of hard coding localhost and the port youll need to use the env vars.
Where local i create variable .env ? In / of the project ?
Thanks Luna. Im trying now.
you dont.. your app has access to the env it's in. all the variables above are exposed to it.
what language are you using?
Im using nodejs
you'll need to use
process.env.
to access them
so process.env.MYSQLHOST
for exampleI set configurations in my index.js but its no change 127.0.2
are you actually using those for the mysql connection?
I'm not sure, but I know that on the railway I have notes for database.
no.. that's a question.. did you change the code to use the envs or are you just logging them?
The code you showed above doesn't show you using them.
This print above is show my actualy code in index.
i create too .env in my dir /
okay.. you dont need a .env
this is my .env
you just need to use the
process.env
in your code.I commit .env and index.js but is the same problem. Is necessary using in other file. Im using exclusive in index.js
1. DO NOT commit .env files
2. you DO NOT need a .env file
3. use the
process.env.
in your code to connect instead of hardcoding it.
Until you do those steps you're stuck bud.
Railway automatically puts all the vars from this in process.env for you
just use them.Okay i delete my file .env . What should I do now?
like ive said multiple times... when you connect to mysql use the process.env. vars to connect do not hardcode localhost.
its not going to work until you do that.
I would suggest doing some research on how
process.env
works in nodejs.Okay Luna. I do searches. Thanks for help me.
are you having fun?
Okay Luna. I success. Thank you for help me. Basically i change configs the url. In the past i try send requestions sending url of my backend. Now i change for localhost. This appointment its sucess http://localhost:3001/. After works on my machine, i change requests on my pages frontend and commit. Resolved.