'server does not response data in Node JS

I write a router it is pretty straightforward it goes to service and the service connects to the database and the last router responds to a message and data but it doesn't show anything.

The router is like

router.get(
  "/:id",
  wrap(async (req: Request, res: Response, next: NextFunction) => {
    const id = parseInt(req.params.id);
    const result: any = await StudentService.get(id);
    res.status(200).send({
      message: 'Data serve successfully',
      data   : result
  })
  })
);

and the service class is

export class StudentService {
  constructor() {}

  async get(id: number) {
    const queryText = `select * from temp.student_info where id=$1`;
    const connection = await pgConnect.getConnection("slave");
    const result = await (
      await connection.query(queryText, [id])
    ).rows[0];

    return result;
  }
}

in response, it's just waiting but didn't give any data. if I write a console before res.status like below

router.get(
  "/:id",
  wrap(async (req: Request, res: Response, next: NextFunction) => {
    const id = parseInt(req.params.id);
    const result: any = await StudentService.get(id);
    console.log(result)
    res.status(200).send({
      message: 'Data serve successfully',
      data   : result
  })
  })
);

Then I can see the console but I did not get any response. how can solve this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source