please look at my question !!!! 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 should work and it shows "SUCCESS! Received kilo via foxtrot" how to change it ?
please look at my question !!!!
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 should work and
it shows "SUCCESS! Received kilo via foxtrot"
how to change it ?
Step by step
Solved in 3 steps with 1 images