How do i connect my linode vps to my database

I am trying to connect my linode vps to my database through node js. I have been trying for a while, but to no avail.
Whenever I try to connect, I always get the same error message:
"Failed to load resource: the server responded with a status of 502 (Bad Gateway)"
I have installed all the packages, but it still gives me this, everything is whitelisted, but it does not provide any help.

The code i am using is this one:

const mysql = require('mysql');
const connection = mysql.createConnection({
host: "",
user: 'linroot',
password: "[redacted]",
port: 3306,
ssl: "required",

If there is anything that i should change that i cant see, then pls just point it out, i am new to this, and i am more or less willing to take a whole new approach

1 Reply

Looking over your connection code block, I noticed that you have not named the database and you are including ssl: "required",. With this in mind, there are a few things you'll want to add to your code:

var fs = require('fs');
var mysql = require('mysql');
var connection = mysql.createConnection({
  host: '<>',
  user: 'linroot',
  password: '<your-linroot-password>',
  port: 3306,  
  ssl  : {
    ca : fs.readFileSync('</path/to/CA/cert/file>'),
    rejectUnauthorized: true
connection.connect(function(err) {
  if (err) throw err;

You will need to download a copy of your SSL certificate from the Cloud Manager and add the path to your code.

You can check out this post on stack overflow that has a bit more information. Additionally, if you're still having trouble after you add that code, I suggest reaching out to other NodeJS users on the NodeJS GitHub Discussions page.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct