1
I’m trying to read parameters sent via post, but the express only shows on the console.log empty objects.
This is the code
import * as jsonServer from 'json-server'
import {Express} from "express";
import * as fs from 'fs'
import * as https from 'https'
const server: Express = jsonServer.create()
const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()
// Set default middlewares (logger, static, cors and no-cache)
server.use(middlewares)
// To handle POST, PUT and PATCH you need to use a body-parser
// You can use the one used by JSON Server
server.use(jsonServer.bodyParser)
server.post('/login', (req, res, next) =>{
console.log(req.body)
})
// --
// Use default router
server.use(router)
const options = {
cert: fs.readFileSync('./backend/keys/cert.pem'),
key: fs.readFileSync('./backend/keys/key.pem')
}
https.createServer(options, server).listen(3001, () => {
console.log('JSON Server is running on https://localhost:3001')
})
I’m trying to see as Postman’s object
already tried to change in the Postman from "Text" to "JSON"?
– Ricardo Pontual
Where do I make that change?
– adventistaam
Ah found and received the parameters
– adventistaam
I will post as an answer
– Ricardo Pontual
All right, thanks!..
– adventistaam