Thursday 25 July 2019

Why is return required after sending the response (expressjs)?

Hi everyone,I'm learning expressjs and was working with this code snippet for a small tutorial app,​var express = require("express");var app = express();app.get("/random/:min/:max", function (req, res) {var min = parseInt(req.params.min);var max = parseInt(req.params.max);if (isNaN(min) || isNaN(max)) {res.status(400);res.json({ error: "Bad request." });return;}var result = Math.round((Math.random() * (max - min)) + min);res.json({ result: result });});app.listen(3000, function () {console.log("App started on port 3000");});Now, inif (isNaN(min) || isNaN(max)) {res.status(400);res.json({ error: "Bad request." });return;}Why do we require return after returning response?

Submitted July 25, 2019 at 12:17PM by jay-random

No comments:

Post a Comment