This project is a simple library management system built with Express.js and TypeScript. It includes functionality for managing users, books, and borrow records, with caching implemented using Redis for efficient book viewing.
- Node.js (v14.x or later)
- PostgreSQL
- Redis
-
Clone the repository:
git clone https://github.com/alicanuzun/invent-library-ms.git cd invent-library-ms
-
Install dependencies:
npm install
-
Ensure PostgreSQL is installed and running on your system.
-
Create the necessary tables:
CREATE TABLE users ( id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text NOT NULL, created_dt timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE books ( id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text NOT NULL, is_available boolean NOT NULL DEFAULT true, created_dt timestamp with time zone DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE borrows ( id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, user_id integer NOT NULL REFERENCES users(id), book_id integer NOT NULL REFERENCES books(id), borrow_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, return_date timestamp with time zone, score integer );
-
Update the database connection settings in
./config/config.json
to match your PostgreSQL setup.
- Ensure Redis is installed and running on your system. Follow the instructions below to install Redis.
Install Redis using Homebrew:
```sh
brew install redis
```
Install Redis using the package manager:
```sh
sudo apt update
sudo apt install redis-server
```
You can use the Windows Subsystem for Linux (WSL) to install Redis on Windows, or download the Redis setup from Microsoft archive.
For WSL, you can follow the Ubuntu installation steps within your WSL terminal.
- Start the Redis server:
```sh
brew services start redis
```
```sh
sudo systemctl start redis
sudo systemctl enable redis
```
If you used WSL, you can start Redis from the WSL terminal:
```sh
redis-server
```
If you used the Redis setup for Windows, run Redis from the installed application.
-
Verify the Redis server:
redis-cli
You should see a prompt like this:
```
127.0.0.1:6379>
```
Type ping
and press Enter. You should get a PONG
response, indicating that the Redis server is running.
-
Install the Redis client for Node.js:
npm install redis
-
Create a
.env
file in the root directory of the project. This file will store your environment variables. -
Add the following environment variables to the
.env
file:PORT=3000 REDIS_URL=redis://localhost:6379
PORT
: The port number for your Express.js server.REDIS_URL
: The URL for your Redis server.
-
Start the Redis server on your local machine:
redis-server
-
Start the PostgreSQL server on your local machine.
-
Start the Express.js server:
npm start
The server should now be running on http://localhost:3000
.
- The project uses
express-validator
for request validation. - Sequelize ORM is used for database interactions.
- The project uses TypeScript for type safety.