Saving express() in the app variable

Hello, when working with express the first two lines of the js file are usually the following:

var express = require('express');
var app = express();

Why is it necessary to save express() in app? Why would you use not say express().use() for example?

Is this just an arbitrary convention?

I think the second answer is particularly helpful:

You will be using the same express() instance in app multiple times (for listening and HTTP methods (https://expressjs.com/en/starter/basic-routing.html), as it saves (stores) a single instance of the function express into a variable.

If you do express().use() instead along with other methods on express(), you will be creating multiple instances/applications.

In terms of naming it app, I guess you can name it something else, but it is convention, as you are building a web app (Express is a web application framework on node.js).

2 Likes

Ok, that makes sense. Thank you!