A RESTful backend API for a video rental application built using Node.js, Express, and MongoDB.
This project was built as a backend service to practice designing and implementing secure REST APIs using Node.js and MongoDB with proper validation, authentication, and logging.
Application data is stored in MongoDB Atlas and accessed through Mongoose.
The API is intended to be consumed by client applications or tested using tools such as Postman.
The API is deployed on Render:
https://vidly-8skn.onrender.com/api/
This endpoint is intended to be accessed through tools like Postman or integrated directly into applications that consume the API.
- Node.js
- Express.js
- MongoDB
- MongoDB Atlas (Cloud Database)
- Mongoose
- JSON Web Tokens (JWT)
- bcrypt (Password Hashing)
- Joi Validation
- Winston Logging
- Postman (API Testing)
- RESTful API architecture
- JWT-based authentication and authorization
- Role-based access control for admin operations
- CRUD operations for:
- Movies
- Genres
- Customers
- Rentals
- Users
- Password hashing using bcrypt
- Request validation using Joi
- Centralized error handling middleware
- Logging using Winston
vidly/
│
├── README.md ← project overview
├── API.md ← API endpoint documentation
│
├── config/
├── middleware/
├── models/
├── routes/
├── startup/
│
├── index.js
└── package.json
For complete API endpoint documentation and usage examples, see:
API Endpoints → API.md
The application requires the following environment variables:
MONGO_URI=your_mongodb_connection_string
JWT_PRIVATE_KEY=your_jwt_secret_key
PORT=3000
These variables can be configured in two ways:
- By creating a
.envfile in the project root. - By setting them as environment variables in the terminal.
Refer to the Setting Environment Variables section below for platform-specific commands.
The application reads the MongoDB connection string using:
process.env.MONGO_URI
This value is used in the database configuration (startup/db.js) and logging configuration (startup/logging.js).
You can connect using either:
MongoDB Atlas
If you are using MongoDB Atlas, assign your Atlas connection string to MONGO_URI.
Example in .env:
MONGO_URI=your_atlas_connection_string
or set it using environment variables as shown in the Setting Environment Variables section below.
Local MongoDB
If MongoDB is installed locally and running on port 27017, the connection string will be:
mongodb://localhost:27017/vidly
You should assign this value to the MONGO_URI variable.
Example in .env:
MONGO_URI=mongodb://localhost:27017/vidly
Alternatively, set it using environment variables as shown in the Setting Environment Variables section below.
export JWT_PRIVATE_KEY=your_secret_key
export MONGO_URI=mongodb://localhost:27017/vidly
export PORT=3000
set JWT_PRIVATE_KEY=your_secret_key
set MONGO_URI=mongodb://localhost:27017/vidly
set PORT=3000
The port is not restricted to 3000.
You can assign any available port number.
git clone https://github.com/mabhishek-dev/vidly.git
cd vidly
npm install
You can run MongoDB:
- Locally (for example using Homebrew on macOS)
- Or use MongoDB Atlas
Run using Node:
node index.js
If nodemon is installed globally
nodemon index.js
If nodemon is not installed globally
npx nodemon index.js
Most API endpoints require authentication.
Users must first register or login to obtain a JSON Web Token (JWT).
The token must be included in the request header:
x-auth-token: <JWT_TOKEN>
Permissions:
- Unauthenticated users can only retrieve limited data.
- Registered users can perform operations such as creating or updating resources.
- Certain actions (such as deleting resources) require admin privileges.
For detailed authentication flow and endpoint usage, refer to:
API Documentation → API.md
The API can be tested using Postman.
For detailed endpoint information and request examples, refer to:
API Documentation → API.md
This project is licensed under the MIT License.