Report this

What is the reason for this report?

All old project get connected to the last mysql database created

Posted on March 5, 2021

Hello, After a long search in many platform for someone who have same issue but i didn’t find any solution… i have deployed 2 express api in same droplet using nginx blocks following this tutorial who is really great and thanks to their authors. https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

Now when i end deploying first project everything work fine but when i do same for the other project my second project work fine also but my first project get connected automatically to the second database created.

my .env file on the first project look like this.

HOST=localhost PORT_DB=3306 USER=root PASSWORD_DB=000000 DIALECT=mysql NAME_DB=database1

my .env file on the second project look like this.

HOST=localhost PORT_DB=3306 USER=root PASSWORD_DB=000000 DIALECT=mysql NAME_DB=database2



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.

Your node application might be picking up the wrong .env file for your first project which is why it is connecting to your second database. Each application should have its own unique .env file. Ensure that each application is reading from its own .env file and not from a shared location.

You may want to check your code where you’re initialising the database connection using the .env file, make sure that the path is not hard coded and is reading from the correct location.

Also, consider using process.env to access the environment variables so that the file-path won’t affect.

Here is some useful article that might help you understand how Environment Variables work:

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.