I found this sample code of a nodeJS server. I don't understand what this line of code does, what is the true for:
var urlParts = url.parse(req.url, true)
The following line is also unclear to me. Why is it neccessairy to write data.txt?
fs.writeFileSync("data.txt", data);
SERVER
server = http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin': 'http://localhost'
});
var urlParts = url.parse(req.url, true),
data = urlParts.query.data;
fs.writeFileSync("data.txt", data);
res.end("OK");
});
url.parsetrue enables parsing of the query string nodejs.org/docs/latest/api/url.html