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 trial

JavaScript Build a REST API With Express Modeling Data for the API Connecting Mongoose to MongoDB

Rebekah Shaw
Rebekah Shaw
18,687 Points

Error when connecting to mongod

I have been trying to connect to the mongo server for over an hour but have had no joy. I installed mongoose, mongodb and mongo. when I ender mongod into the terminal I get the following message.

-bash: mongod: command not found

When I enter node mongoose_sandbox.js into the terminal I get the following message.

connection error: { Error: connect ECONNREFUSED 127.0.0.1:27017 at Object._errnoException (util.js:1003:13) at _exceptionWithHostPort (util.js:1024:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1195:14) name: 'MongoError', message: 'connect ECONNREFUSED 127.0.0.1:27017' }

I'm so confused and none of this is clear within the video.

In what directory did you install mongo?

3 Answers

Rebekah Shaw
Rebekah Shaw
18,687 Points

I installed it into the qa-rest-api folder

Rebekah Shaw
Rebekah Shaw
18,687 Points

I'm using OS X, I will try this and let you know if it works

Seth Kroger
Seth Kroger
56,414 Points

The main issue is that mongod wasn't installed in the usual directories where executable files are searched for (the environment variable PATH) and if you installed it in the project's folder you need to specify the directory path to the mongod executable to run it.

Rebekah Shaw
Rebekah Shaw
18,687 Points

where is it meant to be installed?

Are you on a OS X or Windows? On OS X you will want mongod to be installed in usr/local/bin . Same place where node and npm is installed. Your PATH should already expose that directory. I recommend you uninstall it and reinstall it with homebrew. It will add mongod to the correct directory for your.

Here is another guide that should help: It contains the correct way for doing it with Homebrew or Manual download.

https://treehouse.github.io/installation-guides/mac/mongo-mac.html

Rebekah Shaw
Rebekah Shaw
18,687 Points

After doing this I still get the same message.

-bash: mongod: command not found

What operating system are you on? If on OS X if you do echo $PATH in the command line do you see usr/local/bin in the result?

Rebekah Shaw
Rebekah Shaw
18,687 Points

I think I have got it working now, thanks for your help :-)

so um.... could you please share how you got it working?