Next.js Discord

Discord Forum

I am getting my mysql data in console but not in postman

Answered
Saltwater Crocodile posted this in #help-forum
Open in Discord
Original message was deleted.
Answered by Rafael Almeida
if you want to return json, you can do
return NextResponse.json(fruits);
View full answer

5 Replies

Saltwater Crocodile
remade it with express but still cant get the response
const express = require('express');
const router = express.Router();
const db = require('../db');

router.get('/', async (req, res) => {
const connection = await db.getConnection();
const query = SELECT * FROM fruits;
const fruitsPlus = await connection.query(query);
const fruits = fruitsPlus[0];
res.json({data: fruits})
});

module.exports = router;
to return data from route handlers you need to return a Response
if you want to return json, you can do
return NextResponse.json(fruits);
Answer
Saltwater Crocodile
Thank youuuu