-1

I am reading expressjs documentation and i sow that the response to the user can be sent like this:

res.status(404).send('Sorry, we cannot find that!') //or
res.status(201).send('posted')

I want to know if according to best practices, is ok to send the shttp status code like this:

res.send({
  data: {
    user: "John
  },
  statusCode: 201,
  message: "POsted success"
})

It is ok the last structure or it exist another way to send data about the status?
PS: I am new to node js

1 Answer 1

2

The send method doesn't use a statusCode property on the body parameter to determine what the status code should be.

Not only is it not best practise, it simply doesn't work.

Sign up to request clarification or add additional context in comments.

2 Comments

also i am using nestJS (docs.nestjs.com/controllers), do you know how there to send statusCode together with ` data: { user: "John }, message: "POsted success"`... ?
could you help with this please stackoverflow.com/questions/66303961/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.