MongoError : Server 127.0.0.1:3000 timed out at null - node.js

I am getting an error in cmd when i run "node app.js" command.
"facebook-auth\express-authentication" is my path to NodeJS project.
I run my MongoDB and i think it is working fine.
and
When i use "node app.js" command in starting then my "http://127.0.0.1:3000" server work fine but when i close all connections and try to restart mongoDB then is error occur everytime.
I don't know how to solve this problem and this project is running fine in starting on http://127.0.0.1:3000. But don't know what happened know. I closed my MongoDB using Ctrl+C.
After adding this code
// When successfully connected
mongoose.connection.on('connected', function () { console.log('Mongoose default connection open to ' + dbURI); });
// If the connection throws an error
mongoose.connection.on('error',function (err) { console.log('Mongoose default connection error: ' + err); });
to app.js it shows this:
Showing an error and website authentication not work properly(But website is running now). It don't get callback information from localhost or 127.0.0.1. It keeps waiting for response for localhost and callback doesn't complete (stuck there).
I follow this tutorial :Here and project is working fine.
"Is this a conflict between xampp or mongoDB or nodeJS"
App.js file linked Here
Thanks in advance for help.

Waiting for connections on port 27017.
Vs.
Server 127.0.0.1:3000 timed out.
Don't let me think everything is fine.
You either have to change the port, where app.js is connecting to, to Mongo's standard port 27017, or start mongod with --port 3000 to listen on port 3000.

I was facing the same problem and this is what I got each time I run my app.
/home/sarojs/projects/ror/liveProject/bq-ng/brandqast- ng/node_modules/mongoose/node_modules/mongodb/lib/server.js:242
process.nextTick(function() { throw err; })
^
MongoError: server 127.0.0.1:8080 timed out
at null.<anonymous> (/home/sarojs/projects/ror/liveProject/bq-ng/brandqast-ng/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:436:40)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at null.<anonymous> (/home/sarojs/projects/ror/liveProject/bq-ng/brandqast-ng/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:144:10)
at g (events.js:260:16)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at Socket.<anonymous> (/home/sarojs/projects/ror/liveProject/bq-ng/brandqast-ng/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:172:12)
at Socket.g (events.js:260:16)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at TCP._onclose (net.js:469:12)
I found that the mongoDB URI that I was setting was 8080 as port no.
I simply changed the port to 27017 as it is the default port. It worked perfectly fine.

Related

MongoDB refuses Connection on Windows 10 machine

i'm running a Node.js app on my Windows 10 machine. I have Mongoose installed and setup like this:
// Init Database
var mongoose = require("mongoose");
var mongoDB = "mongodb://127.0.0.1/sampledata"
mongoose.connect(mongoDB);
var db = mongoose.connection;
// Check DB connection
db.once("open", function(){
console.log("Connected to MongoDB");
});
// Check for DB errors
db.on("error", function(err){
console.log(err);
});
Now, when I start the server with nodemon, the following error appears in the console:
{ MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
at Pool.<anonymous> (C:\Users\...\node_modules\mongodb-core\lib\topologies\server.js:564:11)
at emitOne (events.js:96:13)
at Pool.emit (events.js:188:7)
at Connection.<anonymous> (C:\Users\...\node_modules\mongodb-core\lib\connection\pool.js:317:12)
at Connection.g (events.js:291:16)
at emitTwo (events.js:106:13)
at Connection.emit (events.js:191:7)
at Socket.<anonymous> (C:\...\node_modules\mongodb-core\lib\connection\connection.js:246:50)
at Socket.g (events.js:291:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1278:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ]
}
When I try to start mongo over the console, I get the following error:
C:\Program Files\MongoDB\Server\4.0\bin>mongo
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
2018-10-03T19:05:24.194+0200 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte (in english: A connection couldn't be established, because the target computer has refused the connection). :
connect#src/mongo/shell/mongo.js:257:13
#(connect):1:6
exception: connect failed
I've never encountered this error before and as stupid as it sounds, yesterday everything worked fine. Haven't changed the code or anything, so it must be an issue with my computer I guess.
Do you guys know what could cause this error?
TL;DR
Start mongod server
mongod
Open another terminal window
Start mongo shell
mongo
Longer Version:
Open Command prompt as an administrator and run netstat -anb, check which port mongodb is listening to (Usually 27017). If you dont see a listing for mongo then it means that mongod is not running, so go ahead and start mongod.exe from the mongodb binaries(or if environment variables are set, run mongod from anywhere on your cmd).
if this doesnt work, your firewall is probably blocking access on that port, so check that out
I was getting this error as well. In my case, I was trying to upgrade to MongoDB 4.0 without first upgrading to 3.6.
Please see https://docs.mongodb.com/manual/release-notes/4.0/#upgrade-procedures if you recently updated MongoDB.

mongoose wont connect to ec2 mongodb instance

i'm trying to create a node.js server that connect to my mongodb hosted on ec2 instance. I'm doing like this :
mongoose.connect("mongodb://username:password#ec2-xx-xx-xxx-xxx.eu-central-1.compute.amazonaws.com:27017/dbname");
db.on('error', err => {
console.log('Mongoose default connection error:', err);
db.close();
});
db.once('open', () => {
console.log(`Mongoose default connection open`);
});
But it keep saying me this error :
Mongoose default connection error: { MongoError: failed to connect to server [xxx] on first
connect [MongoError: connect ETIMEDOUT xxx:27017]
at Pool.<anonymous> (/Users/jmisiti/hm-landing/node_modules/mongodb-core/lib/topologies/server.js:336:35)
at emitOne (events.js:115:13)
at Pool.emit (events.js:210:7)
at Connection.<anonymous> (/Users/jmisiti/hm-landing/node_modules/mongodb-core/lib/connection/pool.js:280:12)
at Object.onceWrapper (events.js:318:30)
at emitTwo (events.js:125:13)
at Connection.emit (events.js:213:7)
at Socket.<anonymous> (/Users/jmisiti/hm-landing/node_modules/mongodb-core/lib/connection/connection.js:189:49)
at Object.onceWrapper (events.js:316:30)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at emitErrorNT (internal/streams/destroy.js:62:8)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)
name: 'MongoError',
message: 'failed to connect to server [xxx] on first connect [MongoError: connect ETIMEDO
UT xxx:27017]' }
My connection string is 100% sure it works. My mongoose version work great with my mongodb version. Any idea ? :)
PS : Ports are open on 27017 and there's already one of my aws instance using my mongodb. So i'm sure it work.
Make sure that you have registered 27017 port in Outbound ports In the EC2 security group.
Then try to access the DB. and if you have already added port and still experiencing the error then check if you MongoDB process is running as a service(i.e. in the background). If not then follow this procedure
Got it. I can't connect from my localhost to my mongodb server (Don't know why) but when i'm connecting to my mongodb server from my ec2 instance it work. So it's fine :)

Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT

I have a sails app. I am running the app in AWS. When i run the code in development mode(sails lift --verbose) it works fine. I am able to access it from the browser bye typing the Ip and port no.(xx.xx.xxx.xx:1337/). But when i run the code in production mode (sails lift --prod --verbose) i am not able to access by ip(xx.xx.xxx.xx) when i try with xx.xx.xxx.xx:1337 it gives me the below error.
Grunt :: Done, without errors.
Unable to parse HTTP body- error occurred:
Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT
at RedisClient.flush_and_error (/home/ubuntu/vka/node_modules/sails/node_modules/connect- redis/node_modules/redis/index.js:142:13)
at RedisClient.on_error (/home/ubuntu/vka/node_modules/sails/node_modules/connect-redis/node_modules/redis/index.js:180:10)
at Socket.<anonymous> (/home/ubuntu/vka/node_modules/sails/node_modules/connect-redis/node_modules/redis/index.js:95:14)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickDomainCallback (node.js:492:13) [Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT]
Unable to parse HTTP body- error occurred:
Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT
at RedisClient.flush_and_error (/home/ubuntu/vka/node_modules/sails/node_modules/connect-redis/node_modules/redis/index.js:142:13)
at RedisClient.on_error (/home/ubuntu/vka/node_modules/sails/node_modules/connect-redis/node_modules/redis/index.js:180:10)
at Socket.<anonymous> (/home/ubuntu/vka/node_modules/sails/node_modules/connect-redis/node_modules/redis/index.js:95:14)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickDomainCallback (node.js:492:13) [Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT]
please suggest a possible solution.
Check if you are hardcoding the host in session.js with ip, change it to localhost.
For your question on how to access without port 1337, You need to set up a reverse proxy, say NginX, open up just the port 80 for public access, configure nginx to route the request coming to port 80 to your sails app running on port 1337, use something like pm2 or forever to run the sails app.
Steps to setup NginX as reverse proxy is explained here: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04

Not able to connect to mongodb when start node server

I am trying to run my node app locally on my VM.
When I am running command:
sudo NODE_ENV= XYZ PORT=80 node server/app.js
I'm getting error:
/node_modules/mongo-oplog/node_modules/mongodb/lib/mongodb/mongo_client.js:378
throw err
^ Error: connection closed
at null. (/node_modules/mongo-oplog/node_modules/mongodb/lib/mongodb/connection/server.js:605:24)
at emit (events.js:92:17)
at null. (/node_modules/mongo-oplog/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:155:15)
at emit (events.js:98:17)
at Socket. (//node_modules/mongo-oplog/node_modules/mongodb/lib/mongodb/connection/connection.js:528:12)
at Socket.emit (events.js:95:17)
My mongoDB is running fine and I can connect to local db with robomongo.
Any help would be highly appreciated on this.

Mongoose Can't Connect Without Internet

I have my MongoDB server running on localhost:27017, and while I can usually run my Node.js app fine, when I disconnect from the internet Mongoose throws the error
Error: failed to connect to [localhost:27017]
Note that I can still connect to the MongoDB server from the Mongo shell client. Also, if I start up my app first and then lose internet connection, my app can access the database fine offline. So why can't it start up without internet?
EDIT: here is the error in full
events.js:85
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
at null.<anonymous> (<My App>\node_modules\mongoose\
node_modules\mongodb\lib\mongodb\connection\server.js:555:74)
at emit (events.js:118:17)
at null.<anonymous> (<My App>\node_modules\mongoose\
node_modules\mongodb\lib\mongodb\connection\connection_pool.js:156:15)
at emit (events.js:110:17)
at Socket.<anonymous> (<My App>\node_modules\mongoos
e\node_modules\mongodb\lib\mongodb\connection\connection.js:534:10)
at Socket.emit (events.js:107:17)
at net.js:923:16
at process._tickCallback (node.js:355:11)
[nodemon] app crashed - waiting for file changes before starting...
Edit: wording
Use 127.0.0.1 instead of localhost. By turning off your wifi interface the OS is no longer able to resolve localhost.
Consider node-offline-localhost.
Add the following before the breaking code:
require('node-offline-localhost').always();
And it just works (hopefully), at least until RFC 3493 gets fixed.
Full disclosure: I authored this package to streamline https in my dev environment when offline.

Resources