Cannot find host name for ElephantSQL server - express

I've been trying to set up an express server. All my routes seem to work correctly, it's connecting to the database that's giving me issues. I'm not great at backend but I feel like getting the host name shouldn't give me this many problems.
Here's my error: (batyr.db.elephantsql.com is my DB_HOST name):
Error: getaddrinfo ENOTFOUND 'batyr.db.elephantsql.com';
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: "'batyr.db.elephantsql.com';"
}
Here's my repository
Here's my knexfile.js:
require('dotenv').config();
const path = require("path");
module.exports = {
development: {
client: 'pg',
connection: {
host: process.env.DB_HOST,
user: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
},
charset: 'utf8',
pool: { min: 1, max: 5 },
migrations: {
directory: path.join(__dirname, "src", "db", "migrations"),
},
},
};
Here's my .env file:
DATABASE_URL = 'postgres://pausapcx:vxSa5l3ZK_F2lrlMGhyt0XBlYbX7hfWY#batyr.db.elephantsql.com/pausapcx';
DB_HOST = 'batyr.db.elephantsql.com';
DB_USERNAME = 'pausapcx';
DB_PASSWORD = '***'; // cut just for this post
DB_NAME = 'pausapcx';
My server.js is running on port 8080, pgAdmin is running on port 5432
Here are the host and server names from elephantsql:
(https://i.stack.imgur.com/CnGQ4.png)
(https://i.stack.imgur.com/EVRkP.png)
I've tried with several differnet host names:
batyr.db.elephantsql.com (pgAdmin accepted this one)
batyr
I've tried the database URL
I've even tried just Elephantsql.com
I've pinged batyr.db.elephantsql.com in the terminal and gotten this response:
Pinging ec2-3-89-203-254.compute-1.amazonaws.com [3.89.203.254] with 32 bytes of data:
Reply from 3.89.203.254: bytes=32 time=41ms TTL=44
Reply from 3.89.203.254: bytes=32 time=76ms TTL=44
Reply from 3.89.203.254: bytes=32 time=38ms TTL=44
Reply from 3.89.203.254: bytes=32 time=37ms TTL=44
Ping statistics for 3.89.203.254:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 37ms, Maximum = 76ms, Average = 48ms
I really suck at backend, I'd appreciate any help.

Was able to get data!
terminal screenshot
The solution was to just swap out all the random connection data with a single database URL (I'll secure it in .env once it's all working)
// works:
connection: 'postgres://pausapcx:***#batyr.db.elephantsql.com/pausapcx',
// doesn't work:
connection: {
host: 'batyr.db.elephantsql.com',
user: 'pausapcx',
password: '***',
database: 'pausapcx',
},

Related

unable to run server, I think it is because I have 2 applications using the same port?

Just Curious (I solved this problem by just using a different port but the issue still triggers me), When I am trying to run the following code:
const app = express();
app.use(bodyParser.json({ limit: "30mb", exteded: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());
const CONNECTION_URL = <correct MongoDB connection url>
const PORT = process.env.PORT || 5000;
mongoose.connect(CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() =>
app.listen(PORT, () => console.log(`Server running on port`+PORT))
).catch((error) => console.log(error.message));
I keep getting an error thrown in my console:
{ code: 'EADDRINUSE', errno: -48, syscall: 'listen', address: '::', port: 5000 }
so after surfing through countless numbers of resources, they all essentially said I had to applications using the same port 5000? So I followed the "solutions" to the problem which all seemed to be killing the Port.
Firstly, I ran:
netstat -avtn | egrep 'Proto|5000'
To get:
Foreign Address (state) rhiwat shiwat pid epid state options
tcp6 0 0 *.5000 *.* LISTEN 131072 131072 1883 0 0x0100 0x00000006
tcp4 0 0 *.5000 *.* LISTEN 131072 131072 1883 0 0x0100 0x00000006
then I tried a few different commands to try and kill.
1) kill -9 $(lsof -t -i:5000)
2) kill <the appropriate pid>
3) kill -9 <the appropriate pid>
However, none of the solutions seemed to work. I even tried the famous computer off and on solution and closed all my applictions but they didn't work either. Does anyone know how I could have solved this without changing my port number?
Two different applications/processes cannot run on the same port. You will need to use different ports to use them parallelly.
Based on your OS there are tons of resources online to kill a process running on a specific port. The process/commands are similar to the ones you have listed to kill a process on a port.

Having troubles connecting sequelize with SQL Server

I'm experiencing some stupid problem while connecting sequelize with SQL Server and the error that is thrown looks something like this :
(node:13096) UnhandledPromiseRejectionWarning: SequelizeConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
at ConnectionManager.connect (E:\ProgramFiles\MojeVjezbe\sidejob_test\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:138:17)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async ConnectionManager._connect (E:\ProgramFiles\MojeVjezbe\sidejob_test\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:318:24)
at async E:\ProgramFiles\MojeVjezbe\sidejob_test\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:250:32
at async ConnectionManager.getConnection (E:\ProgramFiles\MojeVjezbe\sidejob_test\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:280:7)
Here is my configuration for sequelize code :
module.exports = {
//host: "localhost",
database: "testdb",
//server : 'localhost',
dialectModulePath: 'sequelize-msnodesqlv8',
dialect: "mssql",
port : 1433,
dialectOptions : {
//encrypt: true,
InstanceName : "MSSQLSERVER",
//connectionString : 'Server=localhost\MSSQLSERVER01;Database=master;Trusted_Connection=yes;'
},
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
};
As you can see I've tried changing connection string, host, server but the error is still the same. I've also tried enabling TCP/IP for SQL Server and it hasn't worked either.
What am I missing? I don't have a username nor password so I don't think it may be a problem in this case.

peerjs working on loaclhost but not on heroku?

I'm running my node server on 3000 port and peer server on port 3001.In this scenario its working properly.But when deployed over heroku i'm running my server at 3000 and peer server over 443. In this scenario peerjs not wroking. It might be port alloction issue i guess but i'm unable to find the issue.
peer.js
const myPeer = new Peer( {
secure:true,
host: 'my-app-name.herokuapp.com',
port: 443
})
server.js
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => console.log(`Server running on port ${PORT}`));
github link to project : link
New to Heroku. Any help will be appreciated!
Add this to your server file:
var ExpressPeerServer = require("peer").ExpressPeerServer;
var options = {
debug: true,
allow_discovery: true,
};
let peerServer = ExpressPeerServer(server, options);
app.use("/peerjs", peerServer);
And call on client side like this:
var peer = new Peer({
host: "yoursite.herokuapp.com",
port: "",
path: "/peerjs",
});
You Have to Host Two Apps on Heroku. First Your Main App and Second Your PeerJS Server. Because You Cannot Host your App On different Port (i.e. https://your-app-name.herokuapp.com:5000). And Then You can Connect Your Main App PeerJS Client With Your PeerJS Server by using this.
const myPeer = new Peer( {
secure:true,
host: 'my-peerjs-server-name.herokuapp.com',
port: 443
})
Happy Coding!
Just use this Heroku Element to deploy your own peer server with zero configuration. Connect to it from your client providing the host attribute as the url of your Heroku app without the https:// part and you may need to also set secure to true.
{
host: "you_app_name.herokuapp.com", // exclude protocol
secure: true
}
add this in server(index,app) file
const { ExpressPeerServer } = require("peer")
const peerServer = ExpressPeerServer(server, {
debug: true
})
app.use("/peerjs", peerServer);
and in client side add this
const myPeer = new Peer(undefined, {
path: "/peerjs",
host: "/",
port: "443",
})
port should same as your server.listen(port)
This will give invalid frame header for socket io but its fine

Timeout error while connecting to SQL Server: Connection Error: Failed to connect to servername\instancename in 15000ms

The error code is code ETIMEOUT. I am using SQL Server 2014, NodeJs version v12.16.2 and I am running this code in Visual Studio Code.
I have created the database and the table is also created with some records. For the server name, I have also tried giving the FQDN, but it didn't work.
This is the code snippet:
const express = require('express');
const app = express();
var Connection = require('tedious').Connection;
var Request = require('tedious').Request;
app.get('/', function(req, res) {
res.send('<hHii</h');
});
const sql = require('mssql');
var config = {
user: 'domain\username',
password: 'mypwd',
server: 'servername',
host: 'hostname',
port: '1433',
driver: 'tedious',
database: 'DBname',
options: {
instanceName: 'instancename'
}
};
sql.connect(config, function(err) {
if (err)
console.log(err);
let sqlRequest = new sql.Request();
//var sqlRequest = new sql.Request(connection)
let sqlQuery = 'SELECT * from TestTable';
sqlRequest.query(sqlQuery, function(err, data) {
if (err) console.log(err);
console.log(data);
//console.table(data.recordset);
// console.log(data.rowAffected);
//console.log(data.recordset[0]);
sql.close()
});
});
const webserver = app.listen(5000, function() {
console.log('server is up and running....');
});
Error:
tedious deprecated The default value for `config.options.enableArithAbort` will change from `false` to `true` in the next major version of `tedious`. Set the value to `true` or`false` explicitly to silence this message.
node_modules\mssql\lib\tedious\connection-pool.js:61:23
server is up and running....
ConnectionError: Failed to connect to servername\instantname in 15000ms
at Connection.<anonymous(..\SQL\Sample\sample\node_modules\mssql\lib\tedious\connection-pool.js:68:17)
at Object.onceWrapper (events.js:417:26)
at Connection.emit (events.js:310:20)
at Connection.connectTimeout (..\SQL\Sample\sample\node_modules\tedious\lib\connection.js:1195:10)
at Timeout._onTimeout (..\SQL\Sample\sample\node_modules\tedious\lib\connection.js:1157:12)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
code: 'ETIMEOUT',
originalError: ConnectionError: Failed to connect to INPUNPSURWADE\DA in 15000ms
at ConnectionError (..\SQL\Sample\sample\node_modules\tedious\lib\errors.js:13:12)
at Connection.connectTimeout (..\SQL\Sample\sample\node_modules\tedious\lib\connection.js:1195:54)
at Timeout._onTimeout (..\SQL\Sample\sample\node_modules\tedious\lib\connection.js:1157:12)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
message: 'Failed to connect to servername\instantname in 15000ms',
code: 'ETIMEOUT'
},
name: 'ConnectionError'
}
ConnectionError: Connection is closed.
at Request._query (..\SQL\Sample\sample\node_modules\mssql\lib\base\request.js:462:37)
at Request._query (..\SQL\Sample\sample\node_modules\mssql\lib\tedious\request.js:346:11)
at Request.query (..\SQL\Sample\sample\node_modules\mssql\lib\base\request.js:398:12)
at Immediate.<anonymous(..\SQL\Sample\sample\index.js:43:12)
at processImmediate (internal/timers.js:458:21) {
code: 'ECONNCLOSED',
name: 'ConnectionError'
}
Go to Start menu in Windows, search for "Services" and open it.
Look for "SQL Server Browser"
Right click on it and go to Properties.
Switch "Start up type" to "Automatic"
Click Ok
Right click on it again and Start the service.
It should work after that!
You might make a typo in host/port, or the server doesn't listen external interfaces (it might be configured to liten 127.0.0.1 only)
to check that the server is listening to incoming connections, run in terminal the following:
telnet <hostname> <port>
(mac/linux only)
If it says "Unable to connect to remote host: Connection refused" it means the host is there but it doesn't listen the port.
If it says "Unable to connect to remote host: Connection timed out" then the host might not be there, ot doesn't listen to the port.
You may also want to check if your firewall allows connection to that server.

How to fix "errno":"ENOTFOUND" error in smtp configuration using express js

I am trying to configure node mailer in express js application. During the time of sending mail, I got an error ENOTFOUND.
My smpt configurations are,
smtpServer: {
host: "smtp.gmail.com",
port: 587,
secure: false,
user: "email#gmail.com",
pass: "password",
fromName: "",
fromAddress: ""
}
Error :
{"errno":"ENOTFOUND","code":"ECONNECTION","syscall":"getaddrinfo","hostname":"smtp.gmail.com","host":"smtp.gmail.com","port":587,"command":"CONN","meta":{"errno":"ENOTFOUND","code":"ECONNECTION","syscall":"getaddrinfo","hostname":"smtp.gmail.com","host":"smtp.gmail.com","port":587,"command":"CONN"}}
I suspect this error came because of proxy issues. So, I checked the smpt hostname in my machine nslookup table.
That is returned following result:
$ nslookup smtp.gmail.com
Server: 127.0.1.1
Address: 127.0.1.1#53
Non-authoritative answer:
*** Can't find smtp.gmail.com: No answer
Other than else what I missed here?