If you use sequelize as your ORM with postgres database, you may see this error code, especially for first-timer, including me. Found out the problem from this discussion .
Just define the 'port' property with 5432 (default postgres port) will fix the problem.
var orm = new sequelize('database', 'user', 'password', {
dialect: 'postgres',
host: 'localhost',
port: '5432' /* define database port */
});
Related
I have this NodeJS API hosted on App Engine and a MySQL instance on Cloud SQL
I'm using mysql2 and dotenv packages for my connection and for environment variables access, here's how I create the connection:
import mysql from "mysql2";
import * as dotenv from "dotenv";
dotenv.config();
export const db =
process.env.NODE_ENV === "development"
? mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
})
: mysql.createConnection({
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
socketPath: `/cloudsql/${process.env.DB_INSTANCE_NAME}`,
});
I get to this connection creation by reading the official documentation of GCP, when I run it locally it works just fine, but when I deploy the app to App Engine I'm receiving this error:
Error: getaddrinfo ENOTFOUND 172.17.0.1:3306
I think that ip and port are the defaults for the proxy connection or something like that because I'm not setting that ip on any variable
Here's how I set the environment variables on app.yaml
runtime: nodejs14
env: standard
instance_class: F1
automatic_scaling:
min_idle_instances: 1
max_idle_instances: automatic
min_pending_latency: automatic
max_pending_latency: automatic
env_variables:
DB_USER: <db-user>
DB_PASS: <db-pass>
DB_NAME: <db-name>
NODE_ENV: production
DB_INSTANCE_NAME: <db-instance-name>
beta_settings:
cloud_sql_instances: <db-instance-name>
I've already check that the service user has the right permissions and roles
I don't know if I'm missing some configuration or if my app.yaml need another thing
I have tried to add the ip host directly in the connection creation but I'm getting the same behavior
export const db =
process.env.NODE_ENV === "development"
? mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
})
: mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
socketPath: `/cloudsql/${process.env.DB_INSTANCE_NAME}`,
});
I have been fighting with this issue for three days, so any help will be very appreciated for me
Thanks in advance.
const Sequelize = require('sequelize');
const sequelize = new Sequelize('abc', 'abc', 'abc', {
host: 'localhost',
dialect: 'mssql'
});
I am trying to connect the SQLServer from using above code, but getting below error
on sequelize.authenticate()
Unable to connect to the database: { SequelizeConnectionError: Invalid arguments: "instanceName" must be a string
Note: I am using the latest version of sequelize
Example of my connection
const Sequelize = require('sequelize');
const sequelize = new Sequelize('database', 'username', 'password', {
operatorsAliases: Sequelize.Op.Aliases,
freezeTableName: true,
logging: console.log,
dialect: 'mssql',
host: 'host'
});
I wish to know if there is any way of supplying a value for pg_stat_activity.application_name from a Node.js application.
Example: nodejs myapp.js will show: NodeJs - My App
Just as a_horse_with_no_name suggested, putting application_name when you are creating your connection works like a charm in this way:
const client = new Client({
user: 'postgres',
host: 'localhost',
database: 'dbname',
password: 'postgres',
port: 5432,
application_name: 'a name', <---- THIS ONE MAKES THE MAGIC :)
});
So many thanks!
I am new to Orientdb and I am looking to know more about how I can use nodejs with orientdb. Any sites , suggestions , videos will be helpful .. Thanks
You can find some examples in the OrientDB official documentation: https://orientdb.com/docs/2.2/OrientJS.html#orientjs-driver
Anyway, this is an example of connection:
var OrientDB = require('orientjs');
var server = OrientDB({
host: 'localhost',
port: 2424,
username: 'root',
password: 'root'
});
var db = server.use({
name: 'GratefulDeadConcerts',
username: 'root',
password: 'root'
});
server.close();
Hope it helps
Regards
I'm playing around on Heroku and trying to link to a postgres DB. My app is linked directly to the github source code. When I run it locally with the Heroku DB credentials and with npm start it works, but not when it is deployed, I've got this error:
{"name":"SequelizeConnectionError","message":"password authentication failed for user \"riunhwzbjuwwgw\"","parent":
{"name":"error","length":103,"severity":"FATAL","code":"28P01","file":"auth.c","line":"285","routine":"auth_failed"},"original":
{"name":"error","length":103,"severity":"FATAL","code":"28P01","file":"auth.c","line":"285","routine":"auth_failed"}}
Any ideas at all?
Edit : here's the connection
var sequelize = new Sequelize(config.db.dbName, config.db.username, config.db.password, {
host: config.db.host,
dialect: config.db.dialect,
port: config.db.port,
dialectOptions: {
ssl: true
},
logging : false
});
and my variables
db: {
dbName: process.env.DBNAME,
username : process.env.DBUSER,
password : process.env.DBPASSWORD,
host : process.env.DBHOST,
dialect: "postgres",
port : 5432
}
Like I said, it works locally. The password is set like the DBUSER riunhwzbjuwwgw, could it be something those slashes? \"riunhwzbjuwwgw\"