Build Library Management System Using NodeJS (original) (raw)

Last Updated : 30 Mar, 2026

A Library Management System is an essential application for managing books, users, and transactions in a library. It involves adding, removing, updating, and viewing books and managing users.

Core Features of Web Application

Create a simple web application where administrators can manage books and users. The application will feature:

Approach

Below are the approaches for building the Library Management System using Node.js:

Steps to Build a Library Management System

Follow these steps to design and implement a basic library management system using Node.js and related technologies.

Step 1: Create a Project Folder

Open your terminal (Command Prompt/PowerShell) and run the following commands:

mkdir library-management-system cd library-management-system

Step 2: Initialize a NodeJS Project

Run the following command to create a package.json file:

npm init -y

Step 3: Install Dependencies

Run the following command to install the required dependencies:

npm install express ejs body-parser

This installs

Step 4: Create Server File

Create a file named app.js and require the Express module. Then, create an Express instance and set EJS as the default view engine.

JavaScript ``

const express = require('express'); const bodyParser = require('body-parser'); const app = express(); const PORT = 3000;

// Sample Book Data let books = [ { bookName: "Rudest Book Ever", bookAuthor: "Shwetabh Gangwar", bookPages: 200, bookPrice: 240, bookState: "Available" }, { bookName: "Do Epic Shit", bookAuthor: "Ankur Wariko", bookPages: 200, bookPrice: 240, bookState: "Available" } ];

// Middleware app.set('view engine', 'ejs'); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true }));

// Home Route - Display Books app.get("/", (req, res) => { res.render("home", { data: books }); });

// Add Book Route app.post("/", (req, res) => { const newBook = { bookName: req.body.bookName, bookAuthor: req.body.bookAuthor, bookPages: req.body.bookPages, bookPrice: req.body.bookPrice, bookState: "Available" };

books.push(newBook);
res.render("home", { data: books });

});

// Issue Book Route app.post("/issue", (req, res) => { const requestedBookName = req.body.bookName; books.forEach(book => { if (book.bookName === requestedBookName) { book.bookState = "Issued"; } }); res.render("home", { data: books }); });

// Return Book Route app.post("/return", (req, res) => { const requestedBookName = req.body.bookName; books.forEach(book => { if (book.bookName === requestedBookName) { book.bookState = "Available"; } }); res.render("home", { data: books }); });

// Delete Book Route app.post("/delete", (req, res) => { const requestedBookName = req.body.bookName; books = books.filter(book => book.bookName !== requestedBookName); res.render("home", { data: books }); });

// Start Server app.listen(PORT, () => { console.log(App is running on port ${PORT}); });

``

Step 5: Set Up Views Directory

Create a views folder in your root directory and inside it, create a file called home.ejs.

Step 6: Create the Home Page (home.ejs)

Inside views/home.ejs, add the following code

HTML `

Library Management System

All Books

<% data.forEach(element => { %> <% }) %>
Book Name Book Author Book Pages Book Price Book Availability Issue Return Delete
<%= element.bookName %> <%= element.bookAuthor %> <%= element.bookPages %> <%= element.bookPrice %> <%= element.bookState %> <% if (element.bookState === "Available") { %> Issue <% } %> <% if (element.bookState === "Issued") { %> Return <% } %> Delete

Add Book

Add

`

**Output

node app.js