-1

I am following the Thinkster MEAN Stack tutorial and am stuck at the Testing the Initial Routes section in which, after I have already started the MongoDB using the command "mongod &" I still get this error when I npm start...

/Users/myname/workspace/mean_projects/flappernews/node_modules/mongodb/lib/server.js:236
    process.nextTick(function() { throw err; })

Now it seems as though that this error generally occurs when MongoDB is not started or not connected but I have used the

mongod & 

command in my terminal like the tutorial suggested. How do I make sure that my app is connected to my local database on npm start and get past this error.

Here is how I setup the top portion of my app.js

var mongoose = require('mongoose');
require('./models/Posts');
require('./models/Comments');

mongoose.connect('mongodb://localhost/news');

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();
...

I believe the "mongoose.connect('mongodb://localhost/news');" part is what is giving me the error.

Community
  • 1
  • 1
stcho
  • 1,909
  • 3
  • 28
  • 45
  • I usually just navigate to the directory where the mongodb exe files are stored, and run "mongod.exe" and then to confirm that everything is running correctly I run the mongo shell by using "mongo.exe". – Moshe Karmel Jan 10 '16 at 21:35

1 Answers1

2

This error occurs when the mongodb service is not running on mac. I was never connected to the mongodb to begin with. I fixed the issue by running

brew services start mongodb

to connect to mongodb then running "npm start" on the terminal.

Cannot connect to mongodb errno:61 Connection refused

Community
  • 1
  • 1
stcho
  • 1,909
  • 3
  • 28
  • 45