Problem in calls url in my fronn end.

TLThiago Lordello5/15/2023
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 ?
IImLunaHey5/15/2023
did you mean to use 127.0.0.1 instead?
TLThiago Lordello5/15/2023
a297026f-2372-413d-8aa5-0af4cc4fe8bb
TLThiago Lordello5/15/2023
Hi Luna. No, my app is sending to 127.0.2.1:3306
IImLunaHey5/15/2023
1. Why?
2. Are you trying to connect to the local host?
3. Shouldnt you be using env.DATABASE_URL ?
IImLunaHey5/15/2023
🤔
TLThiago Lordello5/15/2023
On my backend i have this log.
IImLunaHey5/15/2023
You're connecting to mysql correct? Are you using a hosted db or one via services in railway?
IImLunaHey5/15/2023
If you're using the mysql service I'd highly suggest reading https://docs.railway.app/databases/mysql
TLThiago Lordello5/15/2023
Yes my database stay in here
IImLunaHey5/15/2023
You likely need to use the envs provided by railway.
IImLunaHey5/15/2023
connecting to localhost isnt going to do anything in this case.
TLThiago Lordello5/15/2023
Okay Luna. Im see this link
TLThiago Lordello5/15/2023
My database there is this varaibles. See
IImLunaHey5/15/2023
yes... now you need to use that in your code.
IImLunaHey5/15/2023
those are all environment variables that're set
TLThiago Lordello5/15/2023
config .json ?
IImLunaHey5/15/2023
no.. in your code.
IImLunaHey5/15/2023
instead of hard coding localhost and the port youll need to use the env vars.
TLThiago Lordello5/15/2023
Where local i create variable .env ? In / of the project ?
TLThiago Lordello5/15/2023
Thanks Luna. Im trying now.
IImLunaHey5/15/2023
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?
TLThiago Lordello5/15/2023
Im using nodejs
IImLunaHey5/15/2023
you'll need to use process.env. to access them
IImLunaHey5/15/2023
so process.env.MYSQLHOST for example
TLThiago Lordello5/15/2023
I set configurations in my index.js but its no change 127.0.2
TLThiago Lordello5/15/2023
IImLunaHey5/15/2023
are you actually using those for the mysql connection?
TLThiago Lordello5/15/2023
I'm not sure, but I know that on the railway I have notes for database.
IImLunaHey5/15/2023
no.. that's a question.. did you change the code to use the envs or are you just logging them?
IImLunaHey5/15/2023
The code you showed above doesn't show you using them.
TLThiago Lordello5/15/2023
This print above is show my actualy code in index.
TLThiago Lordello5/15/2023
i create too .env in my dir /
TLThiago Lordello5/15/2023
IImLunaHey5/15/2023
okay.. you dont need a .env
TLThiago Lordello5/15/2023
this is my .env
IImLunaHey5/15/2023
you just need to use the process.env in your code.
TLThiago Lordello5/15/2023
I commit .env and index.js but is the same problem. Is necessary using in other file. Im using exclusive in index.js
IImLunaHey5/15/2023
1. DO NOT commit .env files
IImLunaHey5/15/2023
2. you DO NOT need a .env file
IImLunaHey5/15/2023
3. use the process.env. in your code to connect instead of hardcoding it.
IImLunaHey5/15/2023
Until you do those steps you're stuck bud.
IImLunaHey5/15/2023
Railway automatically puts all the vars from this in process.env for you
IImLunaHey5/15/2023
just use them.
TLThiago Lordello5/15/2023
Okay i delete my file .env . What should I do now?
IImLunaHey5/15/2023
like ive said multiple times... when you connect to mysql use the process.env. vars to connect do not hardcode localhost.
IImLunaHey5/15/2023
its not going to work until you do that.
IImLunaHey5/15/2023
I would suggest doing some research on how process.env works in nodejs.
TLThiago Lordello5/15/2023
Okay Luna. I do searches. Thanks for help me.
Bbrody5/15/2023
are you having fun?
TLThiago Lordello5/15/2023
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.