DEV Community

Shodunke
Shodunke

Posted on

FIVE DIFFERENT RESPONSES METHOD

Here are 5 ways to respond to a request in Express.js, explained in simple terms:

  1. res.send(): This is like sending a text message. You can send a simple message, like "Hello!" or a more complex message with data.

  2. res.json(): This is like sending a structured message, like a list or a table. It's useful for sending data that needs to be organized.

  3. res.render(): This is like sending a letter with a template. You can fill in the blanks with data, and it will look nice and formatted.

  4. res.redirect(): This is like saying, "Hey, go look over there!" It sends the user to a different webpage.

  5. res.end(): This is like saying, "That's all, folks!" It ends the conversation, and the user's browser will stop waiting for more data.

Top comments (0)