skuyjs/http-server

Request body with JSON data received as a string

Closed this issue · 0 comments

Can't treat the json in request body as an object, because it's not serialized internally.

Code

server.post('/', (req, res) => {
  const { username } = req.body;
  console.log(typeof req.body);
  res.json({
    message: `Hello ${username}`
  });
});

Request

POST /

{
	"email": "tes@mail.co",
	"password": "123123"
}

Response

{
  "message": "Hello undefined"
}

In Console

string