title: Javascript: REST API Mongodb not connecting on Postman
body: <p>I'm new to JavaScript and I'm trying to learn how to build REST API's from a local server on my computer.  When I test the GET request on Postman, however, it always comes back with an error:  Could Not Get Any Response.</p>
  
  <p>The purpose of the REST API is to (a) Store basic information about the planets in the solar system, (b) allow GET requests and (c) allow me to use POST to add more entries in the database.</p>
  
  <p>When I go to postman I use the following URL:  <code>localhost:8000/planets</code></p>
  
  <p>I'm using mongodb and mongoose.  I assume the problem is somewhere in my code because I'm not getting a response from the Server but I can't pinpoint where the problem is.  Thanks.</p>
  
  <pre><code>    var express = require('express');
  var bodyParser = require('body-parser');
  var _ = require('lodash');
  var mongoose = require('mongoose');
  
  var app = express();
  
  app.use(express.static('planet_pages'));
  
  app.use(bodyParser.urlencoded({extended: false}));
  
  app.use(bodyParser.json);
  
  mongoose.Promise = global.Promise;
  var promise = mongoose.connect('mongodb://localhost/planet_server', {
    useMongoClient: true,
  });
  
  promise.then(function(db){
    console.log('DATABASE CONNECTED!!');
  }).catch(function(err){
    console.log('CONNECTION ERROR', err);
  });
  
  var Schema = mongoose.Schema;
  
  var planetSchema = new Schema({
    name: String, 
    position: String, 
    moons: String,
    diameterInKm: String,
    daysInYear: String,
    temperature: String 
  })
  
  var Planet = mongoose.model('Planet', planetSchema);
  Planet.collection.drop();
  
  //*****RAW DATA*****
  
  var planets = [{
    name: "Mercury",
    position: "Mercury is the first planet from the Sun",
    moons: "Mercury has no moons",
    diameterInKm: "Mercury's diameter is 4,879km",
    daysInYear: "A year on Mercury lasts just 88 days!",
    temperature: "The temperature on Mercury is a scorching 427C"},
  
    { name: "Venus",
      position: "Venus is the second planet from the Sun",
      moons: "Venus has no moons",
      diameterInKm: "Venus's diameter is 12,104km",
      daysInYear: "A year on Mercury lasts 225 days!",
      temperature: "The temperature on Mercury is 467C. Hot enough to melt lead!"
  }];
  
  //*****END OF RAW DATA*****
  
  app.get('/planets', function(req, res){
    Planet.find({}).exec(function(err, planets){
      if(err) {
        return res.status(500).send(err);
      }
      return res.json(planets);
    });
  });
  
  app.listen(8000, function(){
    console.log('I am listening');
  });
  </code></pre>
  
  <p>EDIT:  in the line <code>app.use(express.static('planet_pages')</code>, planet_pages is a folder inside my project folder which contains a couple of HTML pages that I hope to use to make AJAX queries.  </p>
  
  <p>Also, supplementary question, in the line <code>app.get('/planets', function(req, res)</code> I'm using <code>/planets</code> as the extension because that's the name of the URL that holds my data in the //*****RAW DATA section.  I got this from following a tutorial but I'm not sure why I'm supposed to do it.  If anyone could explain this I'd MASSIVELY appreciate it.  Thanks.</p>
  
  <p>Also I was advised to use the <code>Planet.collection.drop()</code> to ensure the database refreshes properly when I re-load or make a change to the database.  Since I can't even make the GET request work, I'm not sure if I need this line.</p>
  
  <p>Also, I've not put the POST request code in yet because I don't see the point until I can get the GET request function working.</p>