This project is a robust backend system for managing users, roles, permissions, and blog posts. It's built with Node.js, Express, and MongoDB, utilizing TypeScript for type safety and improved developer experience.
This project was created as part of a YouTube tutorial. To get a detailed walkthrough of the project and learn how to build it step by step, check out our video:
Don't forget to like, subscribe, and leave a comment if you find the tutorial helpful!
- User authentication and authorization
- Role-based access control (RBAC)
- User management (CRUD operations)
- Blog post management (CRUD operations)
- Custom middleware for authentication and role-based permissions
- MongoDB integration for data persistence
- TypeScript for enhanced type checking and code quality
- Node.js
- Express.js
- TypeScript
- MongoDB
- Mongoose (ODM)
- JSON Web Tokens (JWT) for authentication
The project is organized into several key directories:
src/
: Contains the TypeScript source codecontrollers/
: Handles request processing and response generationmiddlewares/
: Custom middleware for authentication and permissionsmodels/
: Mongoose models for database interactionrepositories/
: Data access layer for database operationsroutes/
: API route definitionsservices/
: Business logic layertypes/
: TypeScript type definitions
dist/
: Compiled JavaScript code@types/
: Custom type definitions for external libraries
- Node.js (v14 or later recommended)
- MongoDB
-
Clone the repository:
git clone https://github.com/your-username/your-repo-name.git
-
Install dependencies:
npm install
-
Set up your environment variables (create a
.env
file in the root directory):MONGODB_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret
-
Build the TypeScript code:
npm run build
-
Start the server:
npm start
The API provides endpoints for user management, authentication, role management, and blog post operations. You can use tools like Postman or the provided HTTP files (auth.http
, users.http
, roles.http
, posts.http
) to interact with the API.
- Authentication:
/api/auth/login
,/api/auth/register
- Users:
/api/users
- Roles:
/api/roles
- Posts:
/api/posts
Refer to the route files for a complete list of available endpoints and their functionalities.
For development, you can use the following npm scripts:
npm run dev
: Starts the development server with hot-reloadingnpm run build
: Compiles TypeScript to JavaScriptnpm start
: Starts the production server
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License.
- Express.js for providing a robust web application framework
- MongoDB for efficient data storage
- TypeScript for enhancing code quality and developer experience