Answer the question
In order to leave comments, you need to log in
What is the correct command for node.js?
Good evening, I'm trying to get the server to change the request's url, but all to no avail.
var http = require("http");
http.createServer(function(req, res) {
// initialize the body to get the data asynchronously
req.body = "";
// get the data of the body
req.on('data', function (chunk) {
req.body += chunk;
console.log(chunk);
});
//all data
req.on('end', function () {
if ((id = req.url.match("^/hello/([a-z]+)$"))) {
if (req.method == "GET") {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('WE HAVE A WINNER');
}
} else {
res.writeHead(200, {'Content-Type': 'text/plain'});
if(req.url == ""){ res.end('Hello empty url') } else{
res.end("Hello wrong input" + req.url);
}
}
});
}).listen(8080);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question