This is a restful-api for two types of users - ADMIN
, USER
. Two models are implemented: users and to-do lists. You can register/login. You can also reset your passwor, after which you will receive an email. After logging in, each user can create to-do lists. A usual user can perform CRUD operations on their profile and only for their to-do lists, an administrator can perform CRUD operations on any users and to-do lists.
- Node.js (Express.js)
- TypeScript
- SOA
- Rest API
- MongoDB & Mongoose
- CRUD Operation
- API documentation on Swagger
- APIs Authorization (JWT)
- Reset password (Nodemailer gmail)
- CORS
- Field validation
- Error handling
- Mocha, Chai
- Docker
git clone https://github.com/SerhiiNikif/todo-list-express.git
cd todo-list-express
Create an .env
file in the root of the project and fill it with the values from the .env.sample
file.
MONGO_LOCAL_URI=mongodb://localhost:27017/db
MONGO_LOCAL_PORT=27017
NODE_LOCAL_PORT=3000
MONGO_DOCKER_URI=mongodb://mongo:27017/node-app
MONGO_DOCKER_PORT=27017
NODE_DOCKER_PORT=4000
JWT_SECRET=SECRET_VALUE
BCRYPT_SALT=10
EMAIL_HOST=smtp.gmail.com
EMAIL=your_email
GOOGLE_GEN_PASSWORD=your_google_app_password
FROM_EMAIL=your_email
TEXT_FOR_EMAIL=The text of the letter itself
Docker need to be installed in your OS. To install Docker, please click here.
Development:
npm run docker-compose-up:dev
Production:
npm run docker-compose-up:prod
Now, you are ready to test all APIs. Just simply open your browser http://localhost:3000/api-docs.
Please make sure mongoDB Server service is installed and running on your localhost:27017.
npm install
npm run dev-local
Open your browser http://localhost:3000/api-docs.
npm run test
APIs implement access logic for ADMIN
and USER
roles
All APIs are protected by accessToken (JWT).
Authorization: Bearer <accessToken>
When user login sucessfully, an unique accessToken will be returned.
When creating a user, we specify a role and this gives us access to certain APIs.
APIs | Method | Desc |
---|---|---|
/api/auth/registration | POST | Register user account |
/api/auth/login | POST | User Login |
/api/auth/requestResetPassword | POST | Password reset request, send an email to gmail |
/api/auth/resetPassword | POST | Password reset, send an email to gmail |
APIs | Method | Desc |
---|---|---|
/api/users/ | GET | Get all users |
/api/users/ | POST | Create a new user |
/api/users/{userID} | GET | Get a user by ID |
/api/users/{userID} | PATCH | Update a user by ID |
/api/users/{userID} | DELETE | Delete a user by ID |
APIs | Method | Desc |
---|---|---|
/api/todos/ | GET | Get all todos |
/api/todos/ | POST | Create a new todo |
/api/todos/{todoID} | GET | Get a todo by ID |
/api/todos/{todoID} | PATCH | Update a todo by ID |
/api/todos/{todoID} | DELETE | Delete a todo by ID |
APIs | Method | Desc |
---|---|---|
/api/users/ | GET | Get the logged in user |
/api/users/{userID} | PATCH | Update the logged in user by ID |
For this role, the user can only work with those todos that he himself created.
APIs | Method | Desc |
---|---|---|
/api/todos/ | GET | Get all todos |
/api/todos/ | POST | Create a new todo |
/api/todos/{todoID} | GET | Get a todo by ID |
/api/todos/{todoID} | PATCH | Update a todo by ID |
/api/todos/{todoID} | DELETE | Delete a todo by ID |