Use with Node.js
In this guide, we’ll create several containers to manage dependencies and control the initialization order of services in a Node.js application.
Example
Explanation
- Database Container: Connects to the database only if
DB_ENABLE
is set totrue
. The database connection is provided as an API for other containers. - Cache Container: Initializes a cache system if
CACHE_ENABLE
istrue
. This is useful for enabling or disabling caching dynamically. - API Service Container: Depends on both the database and cache containers. It only starts after these dependencies are ready and has access to their APIs.
Conclusion
This example shows how to use app-compose
to manage various services in a Node.js application, helping to control their initialization order and dependencies.