This repository contains a Node.js server built with Express.js and MongoDB. The server provides APIs for managing users, records, and comments. JSON Web Tokens (JWT) are used for user authentication and authorization of certain resources.
- Clone the repository:
git clone https://github.com/viktor-dimitrov/NodeJS-Cyclic-MongoDB.git
cd NodeJS-Cyclic-MongoDB- Install dependencies:
npm install- Configure the database:
The server uses MongoDB to store data. Make sure you have a MongoDB instance to connect to. Update the database settings in the index.js file:
const mongoose = require('mongoose');
const dbURI = 'mongodb://your-mongodb-connection-string';
mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true });Replace 'mongodb://your-mongodb-connection-string' with the connection string to your MongoDB database.
- Start the server:
npm run dev- Node.js
- Express.js
- MongoDB
- Mongoose
- JSON Web Tokens (JWT)
-
index.js: The main file of the application, where the Express server is started, and the database connection function is called. -
routes.js: This file contains the declarations of all routes in the application. It defines routes for users, records, and comments. -
middlewares/authMiddleware.js: This file contains middleware functions for user authentication and authorization checks. -
managers/authManager.js: This file contains the business logic for user operations such as registration and login. -
managers/recordManager.js: This file contains the business logic for record operations. -
managers/commentManager.js: This file contains the business logic for comment operations. -
models/record.js: This file contains the definition of the record model for the database.
Registers a new user in the system.
Parameters:
username: usernamepassword: passwordemail: email addressphone: phone number
Performs user login.
Parameters:
username: usernamepassword: password
Returns information about the logged-in user.
Returns all comments associated with a specific record.
Parameters:
recordId: identifier of the record
Creates a new comment for a given record.
Parameters:
recordId: identifier of the recordtext: comment text
Returns all records in the system.
Returns information about a specific record.
Parameters:
_id: identifier of the record
Creates a new record.
Parameters:
artist: artisttitle: titleyear: yearstyle: styleimageUrl: URL of the record image
Edits a record.
Parameters:
_id: identifier of the record_userId: identifier of the userartist: artisttitle: titleyear: yearstyle: styleimageUrl: URL of the record image
Deletes a record.
Parameters:
_id: identifier of the record_userId: identifier of the user
- Viktor Dimitrov
This project is licensed under the MIT License. See the LICENSE file for more information.
- GitHub Repository: https://github.com/viktor-dimitrov/NodeJS-Cyclic-MongoDB
- Author: Viktor Dimitrov