The application object in Koa is an object containing the Koa application instance. It also contains a list of the middleware functions in the application. It is responsible for managing and executing the middleware in a cascaded manner. It is also responsible for managing some key aspects of the application, as we will soon see in some of the following examples. Here is an excerpt from the Koa official documentation:
The application object also exposes methods for common tasks such as content-negotiation, cache freshness, proxy support, and so on. A useless Koa application that runs on port 1234 can be easily created in just a few lines of code, as shown here:
const Koa = require('koa');
const app = new Koa();
const port = 1234;
app.listen(port, () => {
console.log(`The app is running on port ${port}`);
});
In the preceding application, the application object is referenced by the app variable by instantiating the application with new Koa(). We then use the application object to start the server with app.listen(), one of the various methods exposed on the application object.