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 Completing and Testing the API Test Routes with Postman

James McDonough
James McDonough
15,618 Points

Server not responding to Postman

My initial GET request to /questions worked, but since then Postman will not respond. How do I troubleshoot this?

MacBook-Pro:REST-API-Workshop user$ node app.js
Express server is listening on port 3000
Database connection successful.
GET /questions 200 65.188 ms - 2
POST /questions - - ms - -
POST /questions - - ms - -
POST /questions - - ms - -
^C
MacBook-Pro:REST-API-Workshop user$ node app.js
Express server is listening on port 3000
Database connection successful.
POST /questions - - ms - -
POST /questions - - ms - -
POST /questions - - ms - -
GET /questions - - ms - -
GET /questions - - ms - -

5 Answers

jared eiseman
jared eiseman
29,023 Points

it's possible you don't have a response on the post route? Can you share your code? Wild guess based off your terminal output there your post controller looks something like:

router.post('/route', (req, res) => {
  //do stuff with the req
  res.json(jsonObject); //missing this line? whether it be res.json/res.send etc
});
Nathan Boaldin
PLUS
Nathan Boaldin
Courses Plus Student 12,545 Points

Im having the same issue but I do have a res on my route:

//POST /questions
// Route for creating questions
router.post('/', (req, res, next)=>{
  var question = new Question(req.body);
  question.save(function(err, question) {
    if (err) return next(err);
    res.status(201);
    res.json(question);
  });
});

Any ideas?

Nathan Boaldin
PLUS
Nathan Boaldin
Courses Plus Student 12,545 Points

I solved my issue from above, so I wanted to write this for anyone that may have issues in the future:

Postman gives this error: There was an error connecting to localhost:3000/questions

Why this might have happened:

The server couldn't send a response: Ensure that the backend is working properly

Self-signed SSL certificates are being blocked: Fix this by turning off 'SSL certificate verification' in Settings > General

Proxy configured incorrectly: Ensure that proxy is configured correctly in Settings > Proxy

Request timeout: Change request timeout in Settings > General

My issue was because there was a typo in my Question Schema. So my issue was (Ensure that the backend is working properly). If you have to check your application start at the route that is causing the error then move to any references that are made within that route...and so on.

Peter Gess
Peter Gess
16,553 Points

I am having an issue that I think is similar to the above. When trying to make a GET on localhost:3000/questions I am getting a "not found" error. Below is my code for the GET. Any ideas?

router.get('/', function(req, res, next){
    Question.find({})
        .sort({createdAt: -1})
        .exec(function(err, questions){
            if(err) return next(err)
            res.json(questions)
    })
})

when making routes make sure both the error handler middlewares are the last in order