res.status.json() is not a function in Nextjs

1.9k views Asked by At

I am creating this api endpoint called pincode.js in Nextjs:

export default function handler(req, res) {
  res.status.json([234400, 721302, 110003, 560017]);
}

but it is giving the error : res.status.json() is not a function How to handle this?

1

There are 1 answers

0
Guilherme Gutierres Gallo On BEST ANSWER

status is a function that expects a status code, you should call or omit it.

passing status 200 to it:

export default function handler(req, res) {
  res.status(200).json([234400, 721302, 110003, 560017]);
}

omit status code, and send default one (200, if I'm not mistaken):

export default function handler(req, res) {
  res.json([234400, 721302, 110003, 560017]);
}