December 2018
Intermediate to advanced
642 pages
15h 5m
English
Let's write some simple code to process a request, and just show what was asked. Our main code for the request process will be the following:
// Source file: src/process_request.jsconst http = require("http");http .createServer((req, res) => { // For PUT/POST methods, wait until the // complete request body has been read. if (req.method === "POST" || req.method === "PUT") { let body = ""; req.on("data", data => { body += data; }); req.on("end", () => processRequest(req, res, body)); } else { return processRequest(req, res, ""); } }) .listen(8080, "localhost");// continues...
The processRequest() function will be quite simple, limited to showing its parameters. This kind of code can become helpful if you need to better understand ...
Read now
Unlock full access