1

This is the full error message when I open http://localhost:5000/express_backend

enter image description here

I am trying to send a json object to the server and I got this error.

Below is my server.js

const express = require('express'); //Line 1
const app = express(); //Line 2
const port = process.env.PORT || 5000; //Line 3

app.listen(port, () => console.log(`Listening on port ${port}`)); 

app.use((err,req,res,next)=>{
   res.status(404).json({
       error : {
           message : err.message
      }
   });
})

// create a GET route
app.get('/express_backend', (req, res) => { //Line 9
  res.send(
    {
      name: "Tester one",
      techs: ["React & Redux", "Express", "MySQL"],
      description: "Lorem ipsum doabore et",
      checkin: "09:00",
      checkout:"18:30",
      type:"Known"
  },
  {
      name: "Tester two",
      techs: ["React & Redux", "Express", "MySQL"],
      description: "Lorem ipsum dolor sit amet, consectetet",
      checkin: "09:00",
      checkout:"18:30",
      type:"Blacklisted"
  }
  );
}); 

I am not sure why this is happening, I am trying to send an json objects to the server

3
  • statusCode parameter is missing in response object of /express_backend Commented Oct 19, 2021 at 5:29
  • app.use((err,req,res,next)=>{ res.status(404).json({ error : { message : err.message } }); }) Commented Oct 19, 2021 at 5:33
  • but i have define it ^ Commented Oct 19, 2021 at 5:34

1 Answer 1

1

You have a typo, you lost the brackets [], it should be

res.send([
  {
    name: 'Tester one',
    techs: ['React & Redux', 'Express', 'MySQL'],
    description: 'Lorem ipsum doabore et',
    checkin: '09:00',
    checkout: '18:30',
    type: 'Known',
  },
  {
    name: 'Tester two',
    techs: ['React & Redux', 'Express', 'MySQL'],
    description: 'Lorem ipsum dolor sit amet, consectetet',
    checkin: '09:00',
    checkout: '18:30',
    type: 'Blacklisted',
  },
]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.