Node.js with Express fails to connect to MongoDb - Error: connect ECONNREFUSED -


if don't start connection mongo on port 27017 via mongod in console, when try starting express server following error:

error: connect econnrefused     @ exports._errnoexception (util.js:746:11)     @ tcpconnectwrap.afterconnect [as oncomplete] (net.js:1000:19) 

if connect via mongod in shell, , run node app.js, works fine.

//app.js  var express = require('express'),     app = express(),     mongoclient = require('mongodb').mongoclient;  app.route('/')     .get(function(req, res){                  res.send("hello, world!")         global.db.close();     });  mongoclient.connect('mongodb://localhost:27017/nvps', function (err , database) {     if(err) throw err;      global.db = database;      app.listen(3000, function(){         console.log('express server started on port 3000');     }); }); 

why doesn't mongo connection initiated when go http://localhost:3000/ on machine?


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -