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)