MYSQL2 Connect EconNRefused - javascript

I'm trying to host a discord bot but it requires MYSQL2 as I need to do some database stuff. If I run this bot on my computer, it works fine. However, if I run it on my vps this error shows up:
Does anyone know why this is the case? It works very fine on my computer. I'm really struggling to find the answer. Please let me know if you know the solution to this :) Thanks, Joony.

I ran into a similar problem where the connection was being rejected. Found that changing the host from 'localhost' to '127.0.0.1' solved the problem.
For example:
const db = mysql.createConnection({
host: "localhost",
user: "username",
password: "password",
database: "myDatabase"
});
became:
const db = mysql.createConnection({ host: "127.0.0.1", user: "username", password: "password", database: "myDatabase" });

Related

password authentication failed for user "root", postgresSQL and docker

I'm trying to connect to my database using postgres on docker but it says that the password authentication failed.
My code:
const { Client } = require('pg');
const client = new Client({
host: 'localhost',
port: 5432,
user: 'root',
password: 'root',
database: 'mycontacts',
});
client.connect();
docker command to start the postgres container:
docker run --name postg -e POSTGRES_USER=root2 -e POSTGRES_PASSWORD=root2 -p 5432:5432 -d postgres
Try creating another Postgres container to try and connect and it will work.
Else. password authentication failed while trying to connect into my docker database
It ended up being the postgres that i had installed on my pc.
I uninstalled it and now its working!

Error: The server does not support SSL connections | PostgreSQL + Knex

I have my back-end at Heroku. The connection file looks like this:
const knex = require("knex")({
client: "pg",
connection: {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
port: 5432,
ssl: {
rejectUnauthorized: false,
},
},
});
The listening:
server.listen(process.env.PORT || 5000);
At insomnia:
Insomnia route + body + error message
I'm able to test my application through the Heroku deploy without problems, but locally, i cannot. My env variables are configured, everything works fine, except the localhost requests.
Any ideias?
Just found out the problem guys. My dotenv wasn't working properly. Although my files were in the correct place, exactly how the documentation asks for, my .env wasn't being recognized (?). I found out this by console logging one of my environment variables. Found out to be undefined, so I pointed out the location of the .env file (default location, above src folder...), and everything started working as it should.

Connecting to postgresql database remotely

how to Connect postgresql using bookshelf.js from a remote system instead of using "host: localhost"
Use the hostname or IP address of the host, instead of 'localhost', like:
host: "dbserver.example.com"
or
host: "203.0.113.1"
Note: if the database is not using the default port (5432) you should also specify it. For example for port 5050:
host: "dbserver.example.com:5050"
or
host: "203.0.113.1:5050"

Finding MongoDB details after hosting on Ubuntu

I'm completely new to setting up servers, MongoDB, and still a little new to Javascript.
I'm trying to upload a Deployd server onto an online server. There is limited information on this, so at the moment, I set up a simple AWS Ubuntu server by doing the following tutorials:
http://zenborgium.blogspot.com/2012/12/how-to-setup-deployd-on-ubuntu-server.html
http://terraltech.com/how-to-setup-deployd-on-ubuntu-server/
However, I'm stuck at creating the production.js. There's a guide on it here. I'm specifically stuck at this line of code:
var server = deployd({
port: process.env.PORT || 5000,
env: 'production',
db: {
host: 'my.production.mongo.host',
port: 27105,
name: 'my-db',
credentials: {
username: 'username',
password: 'password'
}
}
});
server.listen();
Where do I find the host, port, name, and credentials that I should use from MongoDB? The tutorials say I need to use my own data, but I don't know where or how to find them.
First of all, you have to have MongoDB installed. I haven't used Deployd myself, but I will give you some information regarding the config file.
If you are running Mongo on the same ubuntu server as your application, you can use localhost to connect.
Default Mongo install runs on port 27017, in other words localhost:27017.
The 'name' parameter is just a name you give your database. So here you can put whatever you want, ex my-db.
With a clean Mongo install, you don't need any credentials. You have to set that up yourself if you want. I suppose leaving them out of the config file is ok, if not needed.
Your config file should therefor look something like this:
var server = deployd({
port: process.env.PORT || 5000,
env: 'production',
db: {
host: 'localhost',
port: 27017,
name: 'my-db'
}
});
update
I had a quick look at the tutorial you linked to. In one of the tutorials they created a user for mongodb. If you followed this step, you need to put that login information into you connect-object under credentials.
update 2
To get information about your mongodb install, check this SO post

how do i connect an existing database to sequelize.js?

I have a database I generated through postgres. How do I connect it to sequelize for node.js?
I know the basic syntax for sequelize connections, but how do I connect these together?
In node.js after installing the sequelize and pg packages through npm you can do this:
var sequelize = new Sequelize('your_database_name', 'user', 'password', {
host: "localhost", //your server
port: 12345 //server port
dialect: 'postgres'
});
Note, in order to use Sequelize with Postgres you'll_need the postgres package. The Sequelize homepage contains instructions on changes you might need to make in order to use them together.

Categories

Resources