Hello and welcome! This Node.JS challenge project demonstrates a simple architecture building a full API with Node.JS, Express.JS, and MongoDB presents an architectural demo of these features:
- Built with Node.js and Express
- REST API
Route | HTTP Verb | Route Middleware | Description |
---|---|---|---|
/api/users | GET | hasRole('admin') |
Get list of users |
/api/users | POST | Creates a new user | |
/api/users/:id | GET | isAuthenticated |
Get a single user |
/api/users/:id | DELETE | hasRole('manager') |
Deletes a user |
/api/task | GET | Get list of task | |
/api/task | POST | Creates a new task | |
/api/task/:id | GET | Get a single task | |
/api/task/:id | DELETE | Deletes a task | |
/auth/local/login | GET | Login a user |
The use of endpoints is very simple, previously you could see a table of endpoints that you can call, if you need to create a user or log in, here we have some examples.
Request Body:
{
"role": "manager",
"email": "admin@mz.com",
"name": "super admin",
"password": "12345"
}
Response:
{
"profile": {
"name": "SUPER ADMIN",
"role": "manager"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MGFjN2IyNTBjMzRhMmYyMTBmYjRkMTIiLCJpYXQiOjE2MjE5MTY0NTMsImV4cCI6MTYyMjAwMjg1M30.FEme2y4wnvKMzIB_ifIo3FVPU7YkxlNLtsTX8rqSSw4"
}
Request Body:
{
"email": "kz@mz.com",
"password": "12345"
}
Response:
{
"profile": {
"name": "KHRIZTIAN",
"role": "candidate"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MGFjNjM1MTljZjlkNTQ5YjA3YWU2NTEiLCJpYXQiOjE2MjE5MTMyNjIsImV4cCI6MTYyMTk5OTY2Mn0.WkptwtzkfxNu5sQ28idbt4bJ7RDbXvVNlZXF0Z0ht-0"
}
- Git
- Node.js and npm Node >= 14.15.x, npm >= 6.14.x
- MongoDB - Keep a running daemon with
mongod
-
Run
npm install
to install server dependencies. -
Configure the env
$ cp .env.example .env
-
Update
.env
with the required info -
Run
npm run dev
to start the development server.