Error with enviroment variables in an express app
diegotech14
TRIALOP

2 years ago

I'm trying to connect my express API to a MySQL database and the API doesn't recognize the enviroment variables, the names are correctly called and I don't know what is the problem…

Solved

34 Replies

2 years ago

Please provide any errors you are getting and show any relevant code.


diegotech14
TRIALOP

2 years ago

export const PORT = process.env.PORT || 3000
export const DBHOST = process.env.DBHOST || 'localhost'
export const DBUSER = process.env.DBUSER || 'root'
export const DBPASSWORD = process.env.DBPASSWORD || ''
export const DBNAME = process.env.DBNAME || 'dalopcandb'
export const DBPORT = process.env.DBPORT || 3306

export const pool = createPool({
host:DBHOST, user:DBUSER,
password:DBPASSWORD, port:DBPORT,
database:DB_NAME,
})

This is my code, and the env variables of Railway have the same name…


2 years ago

Please provide any errors you are getting.


diegotech14
TRIALOP

2 years ago

{
"message": {
"message": "connect ECONNREFUSED ::1:3306",
"code": "ECONNREFUSED",
"errno": -111
}
}
This is the error


2 years ago

Is this error from the build or deploy logs?

Have you tried console logging those variables?


diegotech14
TRIALOP

2 years ago

This error is ocurrs when I try to query the database

Yeah, I've tried console logging those variables and the variables has the default value, not the process.env.VAR value


2 years ago

Please try to answer all questions I may ask in a comment.


diegotech14
TRIALOP

2 years ago

Please try to answer all questions I may ask in a comment.


2 years ago

Is this error from the build or deploy logs?


diegotech14
TRIALOP

2 years ago

From the build


2 years ago

Please confirm that with a screenshot.


diegotech14
TRIALOP

2 years ago

Sorry currently is from the Deployt logs sometimes appears in it, but not now, but the error is here from the API client

Attachments


2 years ago

Screenshot of your service variables, please.


diegotech14
TRIALOP

2 years ago

Hello, sorry Brody, my internet dies and I can't continue with you…

Attachments


2 years ago

You haven't deployed the changes, so of course you aren't going to be able to read them in code!


Status changed to Solved Railway almost 2 years ago


diegotech14
TRIALOP

2 years ago

Oh..my bad, well I'm new in Railway and in general this is my first try to deploy an API. How can I do that?


2 years ago

Click the Deploy button.


diegotech14
TRIALOP

2 years ago

Okay but I've did that and the error continues…


2 years ago

Screenshot of your service variables, please.


diegotech14
TRIALOP

2 years ago

The service shows "5 changes, edited" How did you tell me, I've saved the changes, but I just clicked the Deploy button and the message still showing


2 years ago

Screenshot of your service variables, please.


diegotech14
TRIALOP

2 years ago

Here..


diegotech14
TRIALOP

2 years ago

sorry

Attachments


2 years ago

You haven't deployed the changes.


diegotech14
TRIALOP

2 years ago

Yeah…but I just clicked the deploy button in the deployments section and nothing happens


diegotech14
TRIALOP

2 years ago

Is this the correct button?

Attachments


2 years ago

No, that says redeploy. Click the Deploy button that appears above the project canvas.


diegotech14
TRIALOP

2 years ago

Sorry brody I feel so fool, look my interface…I can't see that button

Attachments


2 years ago

Well good news, it's not your fault for not seeing it, its your browser's fault, please open your project up in another browser, then you will see the Deploy button.


diegotech14
TRIALOP

2 years ago

Man! you saved my life, thank you so much!


2 years ago

What browser where you using?


diegotech14
TRIALOP

2 years ago

Chrome was the problem, I installed Brave and the button appears


diegotech14
TRIALOP

2 years ago

Thank you Brody, you are a crack!


2 years ago

I use Chrome, it must have been some extension you had interfering with something.


Loading...