This repository contains the source code for an API server that implements Role Based Access Control (RBAC) in Node.js. The server uses Express.js, MongoDB (with Mongoose), and JSON Web Tokens (JWT) for secure authentication.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- A Linux system based on Debian distributions such as Ubuntu (recommended).
- Alternatively, if you're on Windows 10/11, you can use Windows Subsystem for Linux 2 (WSL 2) to create a compatible environment.
Note for WSL users: When using WSL, it's recommended to open your code editor from within the WSL terminal. For instance, if you're using VS Code, navigate to the directory of the repository and run
code .
This command will not only open the current directory in VS Code, but also install VS Code for WSL if it isn't already installed.
- Node.js (v18.0 or later)
- MongoDB (a cloud-based MongoDB service like MongoDB Atlas is recommended)
- Clone the repository:
git clone https://github.com/AbdourahamaneIssakaSani/rbac-system.git
- Change the repository directory
cd rbac-system
- Install NPM packages:
npm install
For development, you'll need to create a .env.development
file in src/config/envs/
and add the following environment variables:
PORT=9000
JWT_ACCESS_SECRET=Your_JWT_ACCESS_Secret
JWT_REFRESH_SECRET=Your_JWT_REFRESH_Secret
JWT_ACCESS_EXPIRES_IN=30d
JWT_REFRESH_EXPIRES_IN=90d
JWT_COOKIE_EXPIRES_IN=90
V1_MONGO_URI=Your_MongoDB_URI
EMAIL_USERNAME=Your_Email_Username
EMAIL_PASSWORD=Your_Email_Password
For other environnement, just use .env.production
or .env.test
Regarding the EMAIL_USERNAME
and EMAIL_PASSWORD
variables, these represent your Gmail SMTP credentials As this application is utilizing Gmail's SMTP server, you'll need to enable the Less secure apps setting on your Gmail account. For evaluators of project, a Google passkey will be provided alongside the project submission for complete functionality.
Remember not to commit
.env
files to your GitHub repository. They should be listed in your.gitignore
file.
After you have installed all dependencies and set up your environment variables, you can start the server using the following command:
npm start
To run in developement environment:
npm run start:dev
To run tests, execute:
npm test
Follow these steps to test the API using Postman:
- Install Postman on your machine or use the web version.
- Import the RBAC System Postman collection.
- Run the requests in logic order described in the documentation.
- Express.js - Fast, unopinionated, minimalist web framework for Node.js
- MongoDB - Source-available cross-platform document-oriented database program
- Mongoose - MongoDB object modeling for Node.js
- jsonwebtoken - An implementation of JSON Web Tokens (JWT)