I am using some code that looks like this since my instructor has forbidden us from using the URL module:
let http = require('http');
http.createServer(function (req, res) {
let request=req.url.split('/');
console.log(request);
}).listen(5000);
}
However, this prints two arrays instead of 1, for the URL
http://127.0.0.1:5000/translate/e2s/this+is+the+url
these look like:
[ '', 'translate', 'e2s', 'this+is+the+url' ]
[ '', 'favicon.ico' ]
I can't index these because they behave as a single array so if I do
request[3].split('+') for instance, I get an error.
Why is this happening and how can I fix this?