Question: ========== URL with hostname and port Request message URL: 0.0.1:3000 Response message: SUCCESS! URL with hostname, port and path echo Request message URL: 0.0.1:3000/echo Response

==========

  1. URL with hostname and port
    1. Request message URL: 0.0.1:3000
    2. Response message: SUCCESS!
  2. URL with hostname, port and path echo
    1. Request message URL: 0.0.1:3000/echo
    2. Response message: SUCCESS! echo
  3. URL with hostname, port, path foxtrot and route parameter value kilo
    1. Request message URL: 0.0.1:3000/foxtrot/kilo
    2. Response message: SUCCESS! Received kilo via foxtrot where the value kilo must be retrieved via the route parameter
  4. Invalid/unexpected URL
    1. Request message URL: 0.0.1:3000/
    2. Response message: FAILED! Fix your URL.

--------------------

i did 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 == "/echo"){ res.write(`SUCCESS!echo ${queryValue}`); res.end(); }

else if(pathname=="/foxrot"){ res.write("FAILED! Fix your URL"); res.end(); } else{

//for any path run this res.write(`FAILED! Fix your URL.`); res.end(); } })

server.listen(port,hostName,()=>{ console.log(`Server running at http://${hostName}:${port}/`); });

------------------------------------

i think this Request message URL: 0.0.1:3000/foxtrot/kilo is incorrect ,how to write this ?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!