for this nodejs router const http = require("http"); const url = require('url'); var hostName = '127.0.0.1'; var port = 3000; var server = http.createServer(function(req,res){ res.setHeader('Content-Type','text/plain'); const parsed = url.parse(req.url); const pathname = parsed['pathname'] const queryObject = url.parse(req.url,true).query; let queryValue = queryObject['name']if(queryValue==null){ queryValue="" } if (pathname=="/"){ res.end("SUCCESS!") } else if (pathname=="/echo"){ res.end("SUCCESS! echo") } else if (pathname=="/foxtrot/:name"){ queryValue = queryObject['name'].toString() res.end("SUCCESS! Received "+queryValue+" via foxtrot") } else{ res.end("FAILED! Fix your URL.") } }) server.listen(port,hostName,()=>{ console.log(`Server running at http://${hostName}:${port}/`); }); -------------- it runs like this picture i wnat to fix it ,when i run http://127.0.0.1:3000/foxtrot/kilo it shows "SUCCESS! Received kilo via foxtrot" how to do it ?
for this nodejs router
const http = require("http");
const url = require('url');
var hostName = '127.0.0.1';
var port = 3000;
var server = http.createServer(function(req,res){
res.setHeader('Content-Type','text/plain');
const parsed = url.parse(req.url);
const pathname = parsed['pathname']
const queryObject = url.parse(req.url,true).query;
let queryValue = queryObject['name']if(queryValue==null){
queryValue=""
}
if (pathname=="/"){
res.end("SUCCESS!")
}
else if (pathname=="/echo"){
res.end("SUCCESS! echo")
}
else if (pathname=="/foxtrot/:name"){
queryValue = queryObject['name'].toString()
res.end("SUCCESS! Received "+queryValue+" via foxtrot")
}
else{
res.end("FAILED! Fix your URL.")
}
})
server.listen(port,hostName,()=>{
console.log(`Server running at http://${hostName}:${port}/`);
});
--------------
it runs like this picture
i wnat to fix it ,when i run
http://127.0.0.1:3000/foxtrot/kilo
it shows "SUCCESS! Received kilo via foxtrot"
how to do it ?
![O 127.0.0.1:3000/foxtrot/kilo
FAILED! Fix your URL.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd7770d6e-352d-49c5-bb02-13e122a27c4b%2F794bf78a-c321-43b1-9a30-3e0f1aa351a3%2Fvnk7oeu_processed.jpeg&w=3840&q=75)
![C O 127.0.0.1:3000
SUCCESS!](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd7770d6e-352d-49c5-bb02-13e122a27c4b%2F794bf78a-c321-43b1-9a30-3e0f1aa351a3%2Fmqnuy4h_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)