By separating app and server in Express, we can separate the API implementation from the network-related configuration. This allows us to carry out API tests without performing network calls. This also guarantees faster test execution and better code coverage metrics.
To achieve this separation, you should declare API and server in separate files. Here we use two files: app.js
and server.js
.