the nodejs server code is like this 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}/`); }); ======================== when i enter http://localhost:3000/foxrot/kilo i hope it to run and display "SUCCESS! Received kilo via foxtrot" but it shows like the picture whats this problem ?how to fix this ?" plz look at my question ,and sure test it
PLEASE LOOK AT MY QUESTION CAREFULLY !
PLEASE LOOK AT MY QUESTION CAREFULLY !
PLEASE LOOK AT MY QUESTION CAREFULLY !
the nodejs server code is like this
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}/`);
});
========================
when i enter http://localhost:3000/foxrot/kilo
i hope it to run and display "SUCCESS! Received kilo via foxtrot"
but it shows like the picture
whats this problem ?how to fix this ?"
plz look at my question ,and sure test it
Step by step
Solved in 2 steps with 1 images