Consider the following two codes:
require('http').createServer()
.on('request', (req, res) => { ... })
.listen(3000, () => console.log("Server running") );
and
const http = require('http');
const server = http.createServer((req, res) => { ... });
server.listen(3000, () => console.log("Server running") );
I have the following questions:
Are there benefits in simply running the first code with chaining functions without assigning to constant or is it better to assign the required HTTP module to
const http, repectively the Server object toconst server? Are the implications regarding how the program will run?Is it better to put the
(req, res) => { ... }request handler inside theonevent handler function for REQUEST event or inside theCreateServerfunction?