Separate Express 'app' and 'server'
One Paragraph Explainer
The latest Express generator comes with a great practice that is worth to keep - the API declaration is separated from the network related configuration (port, protocol, etc). This allows testing the API in-process, without performing network calls, with all the benefits that it brings to the table: fast testing execution and getting coverage metrics of the code. It also allows deploying the same API under flexible and different network conditions. Bonus: better separation of concerns and cleaner code
Code example: API declaration, should reside in app.js
|
Code example: Server network declaration, should reside in /bin/www
|
Example: test your API in-process using supertest (popular testing package)
|
Caught a mistake or want to contribute to the documentation?
Edit this page on Github!