Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNathan Collins
7,429 PointsCan't connect to database
I get the following console error after requiring the database in my app.js file:
/Users/Nate/Documents/Sites/mean-todo/node_modules/mongodb/lib/server.js:242 process.nextTick(function() { throw err; }) ^ Error: getaddrinfo ENOTFOUND localhost localhost:27017 at errnoException (dns.js:26:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)
I've followed the instructions on this video three times and each time I get the same response. I used Homebrew to install MongoDB on my Macbook, and am able to run both mongod and nodemon. After I installed Mongoose, I created the database.js file. The following is the my database.js file:
'use strict';
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/mean-todo', function(err){
if(err){
console.log('Could not connect to MongoDB!');
}else{
console.log('Successfully connected to MongoDB!');
}
});
But again, as soon as I require it in my app.js file (require('./database');), it throws the error. I tried adding ":27017" after "localhost" (I saw that in a SO forum), but that didn't work, either.
2 Answers
jason chan
31,009 Pointsdid you turn on the mongod server?
Nathan Collins
7,429 PointsYes, mongod is running in one tab, and nodemon in a second tab