I'm trying to put in production a site I made with Angular and Express/Sequelize, but always have Sequelize errors :
It works perfectly fine in local with WAMP, I can reach my local database and it's all good.
When I'm trying to use my OVH database (that I got with my hosting plan), I have the following errors :
HostNotFoundError [SequelizeHostNotFoundError]: getaddrinfo ENOTFOUND dodobwtdodob.mysql.db
at ConnectionManager.connect (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:120:17)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async ConnectionManager._connect (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:318:24)
at async C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:250:32
at async ConnectionManager.getConnection (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:280:7)
at async C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\sequelize.js:613:26
at async MySQLQueryInterface.createTable (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\dialects\abstract\query-interface.js:225:12)
at async Function.sync (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\model.js:1300:5)
at async Sequelize.sync (C:\Users\Dorian\Desktop\Développement Web\Mes sites\capitales\server\node_modules\sequelize\lib\sequelize.js:793:35) {
parent: Error: getaddrinfo ENOTFOUND dodobwtdodob.mysql.db
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'dodobwtdodob.mysql.db',
fatal: true
},
original: Error: getaddrinfo ENOTFOUND dodobwtdodob.mysql.db
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'dodobwtdodob.mysql.db',
fatal: true
}
}
I don't understand because I've always used the same config, it works fine when I'm using a PHP PDO object on other projects for example. It doesn't work either on my OVH VPS, where I'm getting connection refused error (even if I had to look at all the tutorials on the net), but that's another problem.
Here is my db.config.js :
module.exports = {
HOST: "dodobwtdodob.mysql.db",
USER: "dodobwtdodob",
PASSWORD: "secretpassword",
DB: "dodobwtdodob",
dialect: "mysql",
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
port:3306
};
And here a part of my index.js :
const dbConfig = require("../config/db.config.js");
const Sequelize = require("sequelize");
const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
host: dbConfig.HOST,
dialect: dbConfig.dialect,
port: dbConfig.port,
pool: {
max: dbConfig.pool.max,
min: dbConfig.pool.min,
acquire: dbConfig.pool.acquire,
idle: dbConfig.pool.idle
}
});
Please change hostname "dodobwtdodob.mysql.db" to ipAddress(host address).
Related
So, I am building a small URL shortener project with js, express, and MongoDB but, I got errors when I'm trying to run my local server and I can't connect to MongoDB!
This is my code:
const express = require('express')
const mongoose = require('mongoose')
const ShortUrl = require('./models/shortUrl')
const app = express();
mongoose.connect('mongodb://localhost/urlShortener', {
useNewUrlParser: true, useUnifiedTopology: true
})
app.set('view engine', 'ejs')
app.use(express.urlencoded({ extended: false}))
app.get('/', async (req, res) => {
const shortUrls = await ShortUrl.find()
res.render('index', { shortUrls: shortUrls })
});
app.post('/shortUrls', async (req, res) => {
await ShortUrl.create({ full: req.body.fullUrl })
res.redirect('/')
})
app.get('/:shortUrl', async (req, res) => {
const shortUrl = await ShortUrl.findOne({ short: req.params.shortUrl })
if (shortUrl == null) return res.sendStatus(404)
shortUrl.clicks++
shortUrl.save()
res.redirect(shortUrl.full)
})
app.listen(process.env.PORT || 5000);
And this is the full log:
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
C:\Users\apsoltanian-pc\Documents\js\url-shortener\node_modules\mongoose\lib\connection.js:807
const serverSelectionError = new ServerSelectionError();
^
MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
at NativeConnection.Connection.openUri (C:\Users\apsoltanian-pc\Documents\js\url-shortener\node_modules\mongoose\lib\connection.js:807:32)
at C:\Users\apsoltanian-pc\Documents\js\url-shortener\node_modules\mongoose\lib\index.js:342:10
at C:\Users\apsoltanian-pc\Documents\js\url-shortener\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (C:\Users\apsoltanian-pc\Documents\js\url-shortener\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (C:\Users\apsoltanian-pc\Documents\js\url-shortener\node_modules\mongoose\lib\index.js:1176:10)
at Mongoose.connect (C:\Users\apsoltanian-pc\Documents\js\url-shortener\node_modules\mongoose\lib\index.js:341:20)
at Object.<anonymous> (C:\Users\apsoltanian-pc\Documents\js\url-shortener\server.js:6:10)
at Module._compile (node:internal/modules/cjs/loader:1099:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'localhost:27017' => ServerDescription {
_hostAddress: HostAddress { isIPv6: false, host: 'localhost', port: 27017 },
address: 'localhost:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 1096791,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED ::1:27017
at connectionFailureError (C:\Users\apsoltanian-pc\Documents\js\url-shortener\node_modules\mongodb\lib\cmap\connect.js:381:20)
at Socket.<anonymous> (C:\Users\apsoltanian-pc\Documents\js\url-shortener\node_modules\mongodb\lib\cmap\connect.js:301:22)
at Object.onceWrapper (node:events:642:26)
at Socket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:164:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
logicalSessionTimeoutMinutes: undefined
}
}
Node.js v17.7.2
[nodemon] app crashed - waiting for file changes before starting...
Thank u guys =)
I was trying to start the small URL-shortener project that I wrote in js, express, and MongoDB but, the problem is that I can't connect to my MongoDB database :(
I solved the problem, so, I replaced localhost with 127.0.0.1 in the connection string and now my problem is solved!
it is because of some ipv6 configurations...
Thank u :)
I'm using a vServer from Ionos for a little project. I installed a MariaDB and NodeJS. Currently I'm trying to connect them both. Here is my code:
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: 'localhost',
user:'root',
password: 'xxxxxxxxx',
database: 'christmastrees',
connectionLimit: 5,
});
async function asyncFunction() {
let conn;
try {
conn = await pool.getConnection();
const rows = await conn.query("SELECT * from bäume");
console.log(rows); //[ {val: 1}, meta: ... ]
} catch (err) {
throw err;
} finally {
if (conn) return conn.end();
}
}
But when executing the file (node app), I get an error message after a few seconds
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
From event:
at _registerHandshakeCmd (/root/server/node_modules/mariadb/lib/connection.js:745:11)
at /root/server/node_modules/mariadb/lib/connection.js:57:11
at new Promise (<anonymous>)
at Connection.connect (/root/server/node_modules/mariadb/lib/connection.js:56:16)
at createConnectionPoolPromise (/root/server/node_modules/mariadb/lib/pool-promise.js:31:8)
at creationTryout (/root/server/node_modules/mariadb/lib/pool-base.js:373:9)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
}
So I searched for help and after 2 hours I literally found only one Idea. I added this line of code to my connection...
port: '/var/run/mysqld/mysqld.sock'
I tryed again to use node app, but this time I didn't get an error message, it is loading forever and nothing happens.
I would be so grateful for any help...
So I found the solution to my problem.
I checked if my MariaDB Service is even running and no it wasn't ^^
Hi I am new with Sequelize ORM. I am following some tutorial and while hands-on, I am facing the problem in connecting the MySQL database with server.
ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:3306
at ConnectionManager.connect (G:\projects\chatApp\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:116:17)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
parent: Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
},
original: Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
}
}
Serve.js
const { ApolloServer } = require('apollo-server')
const { sequelize } = require('./models')
const resolvers = require('./graphql/resolvers')
const typeDefs = require('./graphql/typeDefs')
const server = new ApolloServer({
typeDefs,
resolvers,
})
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
sequelize
.authenticate()
.then(() => console.log('Database connected!!'))
.catch((err) => console.log(err))
})
config.json
{
"development": {
"username": "root",
"password": "root",
"database": "database_dev",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
Can anyone tell me why I am not able to connect to the database?
run MySql installer
reconfigure the MySql Server. it will work fine.
check this out
Check port of mysql you are using, maybe 3307 ?
Unhandled rejection SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
at Promise.tap.then.catch.err (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:123:19)
From previous event:
at ConnectionManager.connect (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:120:13)
at sequelize.runHooks.then (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:311:50)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
From previous event:
at ConnectionManager._connect (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:311:8)
at ConnectionManager.getConnection (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:247:46)
at Promise.try (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:638:36)
From previous event:
at Promise.resolve.retry (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:629:53)
at /Users/wooseungjin/codlab-nodejs/node_modules/retry-as-promised/index.js:70:21
at new Promise (<anonymous>)
at retryAsPromised (/Users/wooseungjin/codlab-nodejs/node_modules/retry-as-promised/index.js:60:10)
at Promise.try (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:629:30)
From previous event:
at Sequelize.query (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:578:23)
at QueryInterface.dropTable (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/query-interface.js:254:27)
at Function.drop (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/model.js:1388:32)
at Promise.each.model (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:873:48)
From previous event:
at Sequelize.drop (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:873:20)
at Promise.try.then (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:798:21)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
From previous event:
at Sequelize.sync (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:796:8)
at Server.app.listen (/Users/wooseungjin/codlab-nodejs/app.js:16:33)
at Object.onceWrapper (events.js:286:20)
at Server.emit (events.js:198:13)
at emitListeningNT (net.js:1313:10)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
I got a problem with using a database (MySQL).
I want to link my web-server and database using express
but there's an error message which is
Unhandled rejection SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
Why does the error appear?
const Sequelize = require('sequelize');
const sequelize = new Sequelize('node_api_codelab', 'root', 'root',{
host: 'localhost',
dialect: "mysql" // pick one of 'mysql','sqlite','postgres','mssql',
});
const User = sequelize.define('user', {
name: Sequelize.STRING
});
module.exports = {
sequelize: sequelize,
User: User
}
the only reason for error that either your SQL server is not running or your node application don't have permission to access it
Check the mySql server status.
sudo service mysql status
or
ps aux | grep mysql
If your server is active Then ,
//Setting up the config
var sequelize = new Sequelize('your-database-name', 'db-username', 'db-password', {
host: 'localhost',
dialect: 'mysql' // pick one of 'mysql','sqlite','postgres','mssql',
port: 3306,
});
//Checking connection status
sequelize.authenticate().complete(function (err) {
if (err) {
console.log('There is connection in ERROR');
} else {
console.log('Connection has been established successfully');
}
});
I am trying call multiple API in request but getting below exception when I am running the application.
Node Version: 10.15.2
NPM Version: 6.4.1
I already set proxy at global level using npm config set http-proxy in the terminal
Exception:
C:\Data\NPM\Testing>node server.js
node.js application starting...
Node HTTP server is listening
One
two
{ Error: getaddrinfo ENOTFOUND mocktarget.apigee.net mocktarget.apigee.net:80
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'mocktarget.apigee.net',
host: 'mocktarget.apigee.net',
port: 80 }
{ Error: getaddrinfo ENOTFOUND httpbin.org httpbin.org:443
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'httpbin.org',
host: 'httpbin.org',
port: 443 }
Code:
var http = require('http');
var async = require('async');
var request = require('request');
console.log('node.js application starting...');
var svr = http.createServer(function (req, resp) {
async.parallel({
one: function (callback) {
console.log("One");
request('http://mocktarget.apigee.net/json', function (error, response, body) {
console.log(error);
});
},
two: function (callback) {
console.log("two");
request('https://httpbin.org/headers', function (error, response, body) {
console.log(error);
});
}
}, function (err, results) {
console.log(results);
});
});
svr.listen(9000, function () {
console.log('Node HTTP server is listening');
});
Please help me how to resolve this issue if anyone knows. Thank you.