This is an Express web application that implements a basic library menagement system.
You can browse and manage:
- Lists of all Books, Authors, Book instances and Genres.
- Detailed pages for each item.
- CRUD funcitonality for all entity types.
- Backend: Node.js + Express
- Database: MongoDB (via Mongoose ODM)
- Templating: Pug
npm installIn the project root, create a file named .env and set your own MongoDB connection string:
MONGODB_URI=<your-mongodb-connection-string>Example MONGODB_URI string for a local database:
MONGODB_URI=mongodb://localhost:27017/librarynpm startWith debug output run:
npm run serverstartthen open http://localhost:3000
This repository contains a Docker Compose setup for running the Express Local Library app together with a MongoDB database. It also includes a populate service for seeding the database with sample data.
- Docker & Docker Compose v2+
- Optional:
.envfile for custom database connection
app– Builds from the included Dockerfile (or uses the prebuilt imagesgusic29/express-locallibrary:latest) and serves the library’s web interface and API.- Builds from
Dockerfileif the image does not exist locally. - Reads database connection from
MONGODB_URIenvironment variable. - Falls back to the internal
mongoservice ifMONGODB_URIis not provided.
- Builds from
mongo– MongoDB 6.0 database- Stores data in a persistent named volume (
mongo-data). - Includes a healthcheck so
appwaits until MongoDB is ready.
- Stores data in a persistent named volume (
populate– One-off container to runnode populatedb.jsand seed the database.- Waits until
mongois healthy before running. - Does not run automatically on
docker compose up(it’s opt-in).
- Waits until
The app reads MONGODB_URI from a .env file in the project root to know which MongoDB instance to use.
MONGODB_URI=mongodb://user:pass@mongo-host:27017/library?authSource=adminIf MONGODB_URI is not set, the app uses the built-in mongo service at:
mongodb://mongo:27017/librarydocker compose up -ddocker compose downMongoDB stores its data in the named volume mongo-data, so data survives container restarts and up/down cycles:
volumes:
- mongo-data:/data/dbto remove the data:
docker compose down -vThe populate service runs populatedb.js to insert sample data. It’s meant to be run manually, not automatically, so you only seed when you want to.
# Make sure mongo is running
docker compose up -d mongo
# Run populate once (container removed after it exits)
docker compose run --rm populate