http.createServer( ) vs app.listen

Hello, I’m trying to learn more about in Node.js. In their documentation they are recommending you to create web appliaction instance using express:

const app = require("express")();

And then create HTTP server like this:

var http = require('http').createServer(app);

As I understand - the http module is a built in node.js module that lets us create http server. But why can’t we use in this example simple app.listen(PORT)?

Express’ app.listen() method is basically a shortcut that invokes http.createServer().
This is what it looks like [from express documentation]:

app.listen = function () {
  var server = http.createServer(this)
  return server.listen.apply(server, arguments)
1 Like