status not found – query parameter nodejs tutorial 4

status not found – query parameter nodejs tutorial 4

 

Source Code

// query parameter if record not found
// import express
const express = require(“express”)
// new app
const app= express()
// new array of fruits
fruits = [“mango”,”banana”,”oranges”,”graps”]
// new route
app.get(“/:index”,(req,res)=>{
// add :index to url- query parameter
// lets check if item not exist in our array
if(!fruits[req.params.index]){
    return res.status(404).send(“Not found”)
}
// now normal response .. if found
res.send(fruits[req.params.index])
})
//listen and serve
app.listen(8080)
Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: