Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Online Library Management System

A full-stack web application for managing a library of books with user authentication.

Features

  • User authentication with JWT tokens
  • Add, edit, delete, and view books
  • Secure password hashing with bcryptjs
  • RESTful API with Express.js
  • MongoDB for data persistence
  • Responsive web interface

Prerequisites

  • Node.js (v14 or higher)
  • MongoDB (local or cloud instance)
  • npm (comes with Node.js)

Installation

  1. Clone the repository

    git clone https://github.com/PavaniP03/Online-Library-Management-system.git
    cd Online-Library-Management-system
  2. Install dependencies

    npm install
  3. Set up environment variables

    cp .env.example .env

    Edit .env and configure:

    MONGODB_URI=mongodb://localhost:27017/online-library
    JWT_SECRET=your_super_secret_key_change_this_in_production
    PORT=3000
    NODE_ENV=development
    
  4. Create a test user (optional)

    Edit createUser.js with desired credentials and run:

    node createUser.js

    Or create through the API after starting the server.

  5. Add sample books (optional)

    Run to populate database with sample books:

    node insertBooks.js

Running the Application

Development

npm start

The application will be available at http://localhost:3000

Default Credentials (if using createUser.js)

  • Username: yourusername
  • Password: yourpassword

Project Structure

.
├── server.js              # Express server and API routes
├── public/
│   ├── index.html        # Frontend HTML
│   ├── scripts.js        # Frontend JavaScript
│   └── styles.css        # Frontend CSS
├── createUser.js         # Utility to create test users
├── insertBooks.js        # Utility to insert sample books
├── package.json          # Dependencies
├── .env.example          # Environment variables template
├── .gitignore            # Git ignore rules
└── README.md             # This file

API Endpoints

Authentication

  • POST /api/login - Login with username and password
    • Body: { "username": "user", "password": "pass" }
    • Returns: { "username": "user", "token": "jwt_token" }

Books (requires authentication)

All book endpoints require the Authorization: Bearer <token> header.

  • GET /api/books - Get all books
  • POST /api/books - Add a new book
    • Body: { "title": "Book Title", "author": "Author Name" }
  • PUT /api/books/:id - Update a book
    • Body: { "title": "New Title", "author": "New Author" }
  • DELETE /api/books/:id - Delete a book

Deployment

Heroku

  1. Create a Heroku app: heroku create your-app-name
  2. Add MongoDB Atlas URI: heroku config:set MONGODB_URI="your_atlas_uri"
  3. Set JWT secret: heroku config:set JWT_SECRET="your_secret_key"
  4. Deploy: git push heroku main

Other Platforms

  • Set environment variables on the hosting platform
  • Ensure MongoDB is accessible
  • Run npm install && npm start

Production Checklist

  • Change JWT_SECRET to a strong, unique key
  • Use MongoDB Atlas or another cloud database service
  • Set NODE_ENV=production
  • Enable HTTPS
  • Set FRONTEND_URL environment variable for CORS
  • Add input validation and sanitization
  • Implement rate limiting
  • Add database backups
  • Monitor application logs

Security Notes

  • JWT tokens expire after 24 hours
  • Passwords are hashed using bcryptjs
  • CORS is configured for security
  • Environment variables should never be committed

Troubleshooting

MongoDB Connection Error

  • Ensure MongoDB is running locally or provide a valid MongoDB URI
  • Check MONGODB_URI in .env

JWT Token Issues

  • Clear browser localStorage: localStorage.clear()
  • Restart the server
  • Verify JWT_SECRET matches between frontend and backend

Port Already in Use

  • Change PORT in .env
  • Or kill process using the port

License

ISC

Author

PavaniP03

Support

For issues or questions, please open a GitHub issue.

About

A Website to maintain library of books

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages