{ [Error: listen EADDRINUSE :::5000] - javascript

What's wrong with the following Server.JS file? We are trying to connect Deployd to Heroku and keep getting the following error. We're using Nitrous, and I have configure the mongoDB port to 5000. Any help is appreciated. Thanks a ton!
Server.JS
// require deployd
var deployd = require('deployd');
// configure database etc.
var server = deployd({
port: process.env.PORT || 5000,
env: 'production',
db: {
host: '0.0.0.0',
port: 5000,
name: 'database_name',
credentials: {
username: 'username',
password: 'password'
}
}
});
// heroku requires these settings for sockets to work
server.sockets.server.set('transports', ["xhr-polling"]);
// start the server
server.listen();
// debug
server.on('listening', function() {
console.log("Server is listening on port: " + process.env.PORT);
});
// Deployd requires this
server.on('error', function(err) {
console.error(err);
process.nextTick(function() { // Give the server a chance to return an error
process.exit();
});
});
ERROR:
db:error Error: Cannot open store: MongoError: server 0.0.0.0:5000 timed out
at /home/nitrous/Find-Volunteerships/node_modules/deployd/lib/db.js:144:17
at /home/nitrous/Find-Volunteerships/node_modules/mongodb/lib/mongo_client.js:330:20
at /home/nitrous/Find-Volunteerships/node_modules/mongodb/lib/db.js:231:14
at null.<anonymous> (/home/nitrous/Find-Volunteerships/node_modules/mongodb/lib/server.js:240:9)
at g (events.js:260:16)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at /home/nitrous/Find-Volunteerships/node_modules/mongodb-core/lib/topologies/server.js:493:23
at commandCallback (/home/nitrous/Find-Volunteerships/node_modules/mongodb-core/lib/topologies/server.js:1149:20)
at Callbacks.flushConnection (/home/nitrous/Find-Volunteerships/node_modules/mongodb-core/lib/topologies/server.js:103:9)
at null.<anonymous> (/home/nitrous/Find-Volunteerships/node_modules/mongodb-core/lib/topologies/server.js:408:24)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at null.<anonymous> (/home/nitrous/Find- Volunteerships/node_modules/mongodb-core/lib/connection/pool.js:144:10)
at g (events.js:260:16)
at emitTwo (events.js:87:13) +0ms
session:error Error removing old sessions: Database connection error +14ms
Unhandled rejection Database connection error
{ [Error: listen EADDRINUSE :::5000]
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 5000 }

You are using same port for two servers.
You can kill one of them with that command
netstat -ano|findstr "PID :5000"
5000 is your port.

Related

Bit.io randomly terminating connecting with node.js

Bit.io randomly terminates connecting with node.js.
When I try to run the following code my node.js works fine for a few minutes but then randomly crashes and gives the error listed at the bottom of this page. I have tried to fix this but I am stuck. Don't know if it's a problem with bit.io or with me. Thanks!!
Code:
const { Client } = require('pg');
const client = new Client({
user: 'process.env.USER',
host: 'db.bit.io',
database: 'process.env.DATABASE',
password: 'process.env.PASSWORD',
port: 5432,
ssl: true,
});
client.connect();
client.query('SELECT * FROM "HPI_AT_state" limit 10;', (err, res) => {
console.table(res.rows);
})
Error:
node:events:491
throw er; // Unhandled 'error' event
^
Error: Connection terminated unexpectedly
at Connection.<anonymous> (node_modules/pg/lib/client.js:132:73)
at Object.onceWrapper (node:events:627:28)
at Connection.emit (node:events:513:28)
at TLSSocket.<anonymous> (node_modules/pg/lib/connection.js:107:12)
at TLSSocket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on Client instance at:
at Client._handleErrorEvent (node_modules/pg/lib/client.js:319:10)
at Connection.<anonymous> (node_modules/pg/lib/client.js:149:16)
at Object.onceWrapper (node:events:627:28)
[... lines matching original stack trace ...]
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
I have figured out the problem. It seems that the issue was because Bit.io terminates the connection if unused for 60 seconds. It was fixed by using Client instead of Pool.
const { Pool } = require('pg');
const pool = new Pool({
user: process.env.USER,
host: 'db.bit.io',
database: process.env.DATABASE,
password: process.env.PASSWORD,
port: 5432,
ssl: true,
});
pool.query('SELECT * FROM "SaveData" limit 10;', (err, res) => {
console.table(res.rows);
});

I have an error with my TCP nodejs server

I wanna make an tcp server with nodejs . When i start the server in the terminal it says nothing, and when i start the client the client gets the message but in the server terminal, it prints:
events.js:292
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
Emitted 'error' event on Socket instance at:
at Socket.onerror (internal/streams/readable.js:760:14)
at Socket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: -54,
code: 'ECONNRESET',
syscall: 'read'
}
When i start the client again, the server is still running, i needed to stop the server using killall node.
How can i fix this error.
Server:
var net = require('net');
var server = net.createServer(function(socket) {
socket.write('Connected to server !\r\n');
socket.pipe(socket);
});
server.listen(1337, '127.0.0.1');
Client:
var net = require('net');
var client = new net.Socket();
client.connect(1337, '127.0.0.1', function() {
console.log('Connected');
client.write('Hello, server! Love, Client.');
});
client.on('data', function(data) {
console.log('Received: ' + data);
client.destroy(); // kill client after server's response
});
client.on('close', function() {
console.log('Connection closed');
});

Connection to server keeps failing connect ETIMEDOUT 94.195.191.104:27017

Each time I try to connect to my server to access the documents in the database, it comes back with a connect ETIMEDOUT error.
I own the server, running Mongo 4.0, have run mongod and left running, there is data in the collection.
let MongoClient = require('mongodb').MongoClient;
let uri = "mongodb://notmyrealusername:notmyrealpassword#thomas.misson.info/tom-portfolio";
MongoClient.connect(uri, { useNewUrlParser: true }, async function(err, db) {
try{
if (err) throw err;
let res = await db.collection("projects").find().count()
console.log(res);
db.close();
}
catch(err)
{
console.log(err);
}
});
Error message:
{ MongoNetworkError: connect ETIMEDOUT 94.195.191.104:27017
at Socket.err (H:\Documents\Personal projects\node_modules\mongodb-core\lib\connection\connect.js:287:16)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
I have opened the port using netsh advfirewall firewall add rule name="Open mongod port 27017" dir=in action=allow protocol=TCP localport=27017
Have now added new interface to the mongod.cfg file.
# network interfaces net:
port: 27017
bindIp: 127.0.0.1, 94.195.191.104

Connect ssh server through nodejs code with ssh key and server name

I have vpn access, so i can ssh to server by following command from terminal
ssh qa-trinath01.my-qa
Its working fine from terminal.
But from nodejs, its not working. my code is
var express = require("express");
var app = express();
var node_ssh = require('node-ssh')
var
ssh = new node_ssh()
ssh.connect({
host: 'qa-trinath01.my-qa',
username: 'tanantham',
port: 27017,
privateKey: '/Users/tanantham/.ssh/id_rsa'
}).then(function() {
console.error('Success: ');
}).catch((error) => {
console.error('ERROR: ', error);
});;
app.listen(3001);
I am getting output as
ERROR: { Error: getaddrinfo ENOTFOUND qa-trinath01.my-qa qa-trinath01.my-qa:27017
at errnoException (dns.js:50:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'qa-trinath01.my-qa',
host: 'qa-trinath01.my-qa',
port: 27017,
level: 'client-socket' }
Can some one suggest the nodejs code to connect to ssh, i have only ssh key and ssh server name details.
ssh key -> /Users/tanantham/.ssh/id_rsa
server name -> qa-trinath01.my-qa
Have you tried to replace 'privateKey' with 'password' and enter your password.
It's probably not the most secure but it normally works.
Unless you have to use your private key from id-rsa
ssh = new node_ssh()
ssh.connect({
host: 'qa-trinath01.my-qa',
username: 'tanantham',
port: 27017,
password: 'YourPasswordHere'
}).then(function() {
console.error('Success: ');
}).catch((error) => {
console.error('ERROR: ', error);
});;
app.listen(3001);

Trouble making nodejs mysql connection

I am trying to make a simple connection between my nodejs server and my mysql db (using Microsoft SQL server manager studio v14), below is my code and the error message appearing in my console window.
here is my code:
var express = require('express');
var app = express();
var sql = require("mssql");
app.get('/', function (req, res) {
// config for your database
var config = {
user: 'superadmin',
password: '***',
server: 'localhost',
database: 'XXX'
};
// connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.query('select * from Schools', function (err, recordset) {
if (err) console.log(err)
// send records as a response
res.send(recordset);
});
});
});
var server = app.listen(5000, function () {
console.log('Server is running..');
});
The error I am getting looks like this:
Server is running..
tedious deprecated The default value for `options.encrypt` will change from `false` to `true`. Please pass `false` explicitly if you want to retain current behaviour. node_modules\mssql\lib\tedious.js:212:23
{ ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
at Connection.tedious.once.err (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\mssql\lib\tedious.js:216:17)
at Object.onceWrapper (events.js:275:13)
at Connection.emit (events.js:182:13)
at Connection.socketError (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\tedious\lib\connection.js:1004:14)
at C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\tedious\lib\connection.js:869:25
at SequentialConnectionStrategy.connect (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\tedious\lib\connector.js:154:9)
at Socket.onError (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\tedious\lib\connector.js:170:16)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
code: 'ESOCKET',
originalError:
{ ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
at ConnectionError (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\tedious\lib\errors.js:12:12)
at Connection.socketError (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\tedious\lib\connection.js:1004:30)
at C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\tedious\lib\connection.js:869:25
at SequentialConnectionStrategy.connect (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\tedious\lib\connector.js:154:9)
at Socket.onError (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\tedious\lib\connector.js:170:16)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at process._tickCallback (internal/process/next_tick.js:174:19)
message: 'Failed to connect to localhost:1433 - Could not connect (sequence)',
code: 'ESOCKET' },
name: 'ConnectionError' }
{ ConnectionError: Connection is closed.
at Request._query (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\mssql\lib\base.js:1299:37)
at Request._query (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\mssql\lib\tedious.js:497:11)
at Request.query (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\mssql\lib\base.js:1242:12)
at C:\Users\smr09\Desktop\Code\ou\db_test\test.js:24:17
at _poolCreate.then.catch.err (C:\Users\smr09\Desktop\Code\ou\db_test\node_modules\mssql\lib\base.js:269:7)
at process._tickCallback (internal/process/next_tick.js:178:7) code: 'ECONNCLOSED', name: 'ConnectionError' }
I am rather new at this particularly with dealing with databases. Can someone explain what the error means?
Add this line to the config:
options: {
encrypt: false
}
It will finally look like:
var config = {
user: 'superadmin',
password: '***',
server: 'localhost',
database: 'XXX' ,
options: {
encrypt: false
}
};
try to put encrypt: false in your config{}, it will work.
your error:
ConnectionError: Failed to connect to localhost:1433 - Could not
connect (sequence)
My problem was resolved by adding port
var config = {
user: 'superadmin',
password: '***',
server: 'localhost',
database: 'XXX',
port: '',
};

Categories

Resources