question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: failed to connect to [localhost:27017]

See original GitHub issue

bug?*

What is the current behavior? i type : npm start at my code dir
If the current behavior is a bug, please provide the steps to reproduce. 0 info it worked if it ends with ok 1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'start' ] 2 info using npm@3.10.10 3 info using node@v6.11.2 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 5 info lifecycle passport-mongo@0.0.1~prestart: passport-mongo@0.0.1 6 silly lifecycle passport-mongo@0.0.1~prestart: no script for prestart, continuing 7 info lifecycle passport-mongo@0.0.1~start: passport-mongo@0.0.1 8 verbose lifecycle passport-mongo@0.0.1~start: unsafe-perm in lifecycle true 9 verbose lifecycle passport-mongo@0.0.1~start: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/home/ahmad/Desktop/DashBord3/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin 10 verbose lifecycle passport-mongo@0.0.1~start: CWD: /home/ahmad/Desktop/DashBord3 11 silly lifecycle passport-mongo@0.0.1~start: Args: [ '-c', 'node ./bin/www' ] 12 silly lifecycle passport-mongo@0.0.1~start: Returned: code: 1 signal: null 13 info lifecycle passport-mongo@0.0.1~start: Failed to exec start script 14 verbose stack Error: passport-mongo@0.0.1 start: node ./bin/www14 verbose stack Exit status 1 14 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:255:16) 14 verbose stack at emitTwo (events.js:106:13) 14 verbose stack at EventEmitter.emit (events.js:191:7) 14 verbose stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14) 14 verbose stack at emitTwo (events.js:106:13) 14 verbose stack at ChildProcess.emit (events.js:191:7) 14 verbose stack at maybeClose (internal/child_process.js:891:16) 14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) 15 verbose pkgid passport-mongo@0.0.1 16 verbose cwd /home/ahmad/Desktop/DashBord3 17 error Linux 4.4.0-89-generic 18 error argv "/usr/bin/nodejs" "/usr/bin/npm" "start" 19 error node v6.11.2 20 error npm v3.10.10 21 error code ELIFECYCLE 22 error passport-mongo@0.0.1 start:node ./bin/www22 error Exit status 1 23 error Failed at the passport-mongo@0.0.1 start script 'node ./bin/www'. 23 error Make sure you have the latest version of node.js and npm installed. 23 error If you do, this is most likely a problem with the passport-mongo package, 23 error not with npm itself. 23 error Tell the author that this fails on your system: 23 error node ./bin/www 23 error You can get information on how to open an issue for this project with: 23 error npm bugs passport-mongo 23 error Or if that isn't available, you can get their info via: 23 error npm owner ls passport-mongo 23 error There is likely additional logging output above. 24 verbose exit [ 1, true ]> passport-mongo@0.0.1 start /home/ahmad/Desktop/DashBord3

node ./bin/www


events.js:160 throw er; // Unhandled ‘error’ event ^

Error: failed to connect to [localhost:27017] at .<anonymous> (/home/ahmad/Desktop/DashBord3/node_modules/mongodb/lib/mongodb/connection/server.js:555:25) at emitThree (events.js:116:13) at emit (events.js:194:7) at .<anonymous> (/home/ahmad/Desktop/DashBord3/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:150:15) at emitTwo (events.js:106:13) at emit (events.js:191:7) at Socket.<anonymous> (/home/ahmad/Desktop/DashBord3/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at emitErrorNT (net.js:1277:8) ahmad@indra-PC:~$ mongo MongoDB shell version: 3.0.15 connecting to: test 2017-12-08T12:59:44.636+0200 W NETWORK Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused 2017-12-08T12:59:44.638+0200 E QUERY Error: couldn’t connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at connect (src/mongo/shell/mongo.js:179:14) at (connect):1:6 at src/mongo/shell/mongo.js:179 exception: connect failed

ip table

`ahmad@indra-PC:~$ sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination
ACCEPT tcp – localhost.localdomain anywhere tcp dpt:27017 state NEW,ESTABLISHED

Chain FORWARD (policy ACCEPT) target prot opt source destination

Chain OUTPUT (policy ACCEPT) target prot opt source destination
ACCEPT all – anywhere anywhere
ACCEPT tcp – anywhere localhost.localdomain tcp spt:27017 state ESTABLISHED

**Please mention your node.js : npm@3.10.10 , mongoose : passport-mongo@0.0.1 /home/ahmad/Desktop/DashBord3 └── mongoose@3.8.23 invalid npm ERR! invalid: mongoose@3.8.23 /home/ahmad/Desktop/DashBord3/node_modules/mongoose

MongoDB version. : db version v3.0.15 git version: b8ff507269c382bc100fc52f75f48d54cd42ec3b **

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13

github_iconTop GitHub Comments

4reactions
moaaxalicommented, Dec 9, 2017

try 127.0.0.1 instead of localhost in your connection string. i.e. “mongodb://127.0.0.1:27017/database_name”

0reactions
aquapicommented, Oct 23, 2021

try 127.0.0.1 instead of localhost in your connection string. i.e. “mongodb://127.0.0.1:27017/database_name” Thanks so much. I spent litterally 2 hours to fixed my server

Read more comments on GitHub >

github_iconTop Results From Across the Web

mongoDB error: Error: failed to connect to [localhost:27017]
Open CMD (In Windows) or terminal (In Ubuntu). type command >cd PATH_FOR_MONGODB_BIN_FOLDER. cd C:\Program Files\MongoDB\Server\3.2\bin.
Read more >
Error: couldn't connect to server 127.0.0.1:27017 - MongoDB
“Error: couldn't connect to server 127.0.0.1 : 27017 ” is a general error message indicating that your client/driver cannot connect to a server...
Read more >
MongoDB – couldn't connect to server 127.0.0.1:27017
Error : couldn't connect to server localhost:27017, connection attempt failed: SocketException: Error connecting to localhost:27017 ...
Read more >
Failed to connect to 127.0.0.1:27017, connection refused
Your log shows errors during service startup, meaning you can't connect to a non-running process. · I found one "solution" Editing the /etc/mongo ......
Read more >
Fix Node.js MongoError: failed to connect to server - Tutorial Kart
mongodb://127.0.0.1:27017 is the base url. Make sure that you are providing the same base URL (same IP and Port) in your Node.js Application....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found