##Backend
This API provides functionalities to manage a library system. It includes endpoints for user authentication and book management, built using Node.js, Express, and MongoDB with Mongoose.
- NodeJs
- Express
- MongoDb
- Mongoose
- JsonWebToken
- Bcrypt
- Cors
To install the project, run:
git clone https://github.com/AgustinFRUni/node-js-course.git
cd mongo-node-course
cd backend
npm install
root/
backend/
└─src/
├── config/
├── controllers/
├── models/
├── routes/
└── validators/
The system follows a client-server architecture and utilizes a MongoDB database managed with Mongoose to handle data storage.
The server is built using Express, and you can find its code in /controllers, /models, /routes and /validators. The client-side implementation is not explicitly mentioned but would generally be included in a separate directory if present.
Additionally, a ./env
file is recommended with the following variables:
PORT
: The port on which the server will listen.JWT_SECRET_WORD
: The secret word used for JSON Web Token (JWT) authentication.CONNECTION_STRING
= The connection string for MongoDB.
Register a new user.
Request Body:
{
"username": "user",
"password": "pass"
}
Authenticate a user and return a token.
Request Body:
{
"username": "user",
"password": "pass"
}
This API uses JSON Web Tokens (JWT) for authentication. To access protected routes, include a valid JWT in the Authorization header of your requests.
Authorization: Bearer your.jwt.token.here
Retrieve all books.
Retrieve aggregated statistics for books, including average price, average pages, and book count by category (requires user authentication).
Retrieve a book by its ID.
Create a new book (requires user authentication).
Request Body:
{
"title": String,
"isbn": String,
"category": String,
"price": Number,
"pages": Number,
"authorName": String,
"yearOfRelease": Number,
"sinopsis": String
}
Update an existing book (requires user authentication).
Delete a book by its ID (requires user authentication).
{
"title": "Cien años de soledad",
"isbn": "9788437604947",
"category": "Novela",
"price": 1200,
"pages": 471,
"authorName": "Gabriel García Márquez",
"yearOfRelease": 1967,
"sinopsis": "Una obra maestra de la literatura hispanoamericana."
}
{
"title": "El amor en los tiempos del cólera",
"isbn": "9788437604817",
"category": "Novela",
"price": 1100,
"pages": 348,
"authorName": "Gabriel García Márquez",
"yearOfRelease": 1985,
"sinopsis": "Una historia de amor que desafía el paso del tiempo."
}
{
"title": "Don Quijote de la Mancha",
"isbn": "9788467031944",
"category": "Clásico",
"price": 1500,
"pages": 980,
"authorName": "Miguel de Cervantes",
"yearOfRelease": 1605,
"sinopsis": "La historia de un caballero idealista y su fiel escudero."
}
{
"title": "Rayuela",
"isbn": "9788437602776",
"category": "Clásico",
"price": 1000,
"pages": 736,
"authorName": "Julio Cortázar",
"yearOfRelease": 1963,
"sinopsis": "Una novela revolucionaria de la literatura latinoamericana."
}
{
"title": "Ficciones",
"isbn": "9788420633127",
"category": "Cuentos",
"price": 800,
"pages": 224,
"authorName": "Jorge Luis Borges",
"yearOfRelease": 1944,
"sinopsis": "Una colección de cuentos llenos de ingenio y profundidad."
}
This part of the project consumes de data given by the backend side presented above, is a regular system with CRUD operations and basic user session management like registering, loggin in and out. It also implements jsonwebtoken for the more sensible operations of the CRUD like creating, updating, deleting and consuming certain data.
- React
- Bulma
- Axios
To run the project: With the repository cloned:
cd mongo-node-course
cd frontend
npm install
npn run dev
This will get the frontend running, is necessary to execute the backend part as well and configure the environment variables.