title: MongoDB setup with node.js: Error: failed to connect to [localhost:27017]
body: <p>I am getting the error:
  "failed to connect to [localhost:27017]" while trying to follow <a href="http://kroltech.com/2013/12/boilerplate-web-app-using-backbone-js-expressjs-node-js-mongodb/">this tutorial</a>.</p>
  
  <p>I've been attempting to do several other node.js tutorials with mongoDB over the past few days, and each one runs into similar problems.
  The other solutions I've found surrounding this all involve people not having the server running when trying to connect. I have mongod running in a terminal window, can view the info in the browser at localhost, and have added and viewed records to the database through the mongo shell. All of that appears to be working. The breakage seems to be in connecting any of the node.js projects to the database, but being pretty new to this, I am not even sure where to begin troubleshooting.</p>
  
  <p>RESOLVED: very stupid mistake on my part. The <a href="https://github.com/mongodb/node-mongodb-native#introduction">file</a> suggested by Neil below (view here was instrumental in helping me to troubleshoot and find the problem, though.</p>
  
  <p>needed to change the line</p>
  
  <pre><code>mongoose.connect('mongodb://localhost/MyApp');
  </code></pre>
  
  <p>to</p>
  
  <pre><code>mongoose.connect('mongodb://127.0.0.1:27017/test');
  </code></pre>
  
  <p>in the server.js file.</p>
  
  <p>Additional note: for reasons I don't quite understand, specifying the address as 127.0.0.1: works, but localhost: does not. </p>