Tutorial "Local Library" website written in Node/Express.
This web application creates an online catalog for a small local library, where users can browse available books and manage their accounts.
For more information see the associated MDN tutorial home page.
Note The auth branch in this repository implements an unsupported and undocumented version of the library with User Authentication and Authorization. This may be a useful starting point for some users.
If you just want to see the finished site, you don't need to set up MongoDB. Install Node.js 24 or later, clone this repo, and run these commands in its root:
npm install
npm run demoThen open http://localhost:3000/. The demo starts a temporary in-memory database and fills it with sample books, authors, genres and book copies. Any changes you make are lost when you stop the server with Ctrl+C. The first run downloads a MongoDB binary, so it may take a minute.
To set the project up for development, with a database that keeps your data:
-
Set up a Node.js development environment (Node.js 24 or later).
-
Make a MongoDB database available. By default the app connects to a local MongoDB server at
mongodb://127.0.0.1:27017/local_library. You can:-
Install MongoDB Community Edition locally.
-
Run MongoDB in Docker, keeping the data in a named volume:
docker run -d --name locallibrary-mongo -p 127.0.0.1:27017:27017 -v locallibrary-data:/data/db mongo:8
-
Use a hosted database such as MongoDB Atlas, and set the
MONGODB_URIenvironment variable to its connection string.
-
-
Once you have node setup install the project in the root of your clone of this repo:
npm install
-
Optionally, add some sample books, authors, genres and book copies to the database:
node populatedb.js "mongodb://127.0.0.1:27017/local_library" -
Run the tutorial server, using the appropriate command line shell for your environment:
# Linux or macOS terminal DEBUG=express-locallibrary-tutorial:* npm run devstart # Windows CMD SET DEBUG=express-locallibrary-tutorial:* & npm run devstart # Windows PowerShell $ENV:DEBUG = "express-locallibrary-tutorial:*"; npm run devstart
The
devstartscript restarts the server when you change a JavaScript file. Usenpm startinstead to run the server without watching for changes. -
Open a browser to http://localhost:3000/ to open the library site.
The project is the result of carefully running through all the steps in the tutorial on MDN. Any changes to either MDN or this project must be synchronized. Generally it is better to implement changes here before submitting them to MDN.
Before submitting a PR, make sure that the tests pass:
npm test