-
Create a NodeJS app.
Use the NodeJS CLI to create a new app, specifying the minimal starter.
# create a new NodeJS site using the minimal starter npm init --y
-
Setting up automatically update server
... "scripts": { ... "start": "nodemon server.js" },
-
Start developing.
Navigate into your new app directory and start it up.
cd [folder_name] npm start
-
Open the code and start customizing!
Your server is now running at http://localhost:3000!
Edit
/server.js
to see your server update in real-time!
bcryptjs: ^2.4.3
cors: ^2.8.5
dotenv: ^10.0.0
express: ^4.17.1
joi: ^17.4.2
jsonwebtoken: ^8.5.1
mysql2: ^2.3.3
nodemon: ^2.0.15
sequelize: ^6.9.0
sequelize-cli: ^6.3.0
Methods | Urls | Actions | Token |
---|---|---|---|
POST | /api/auth/signup | SignUp new Account | - |
POST | /api/auth/signin | Login an Account | - |
GET | /api/user/list | Retrieve Users List Content | Required |
GET | /api/user/find | Retrieve User Content | Required |
PUT / PATCH | /api/user/{id} | Update User Content | Required |
DELETE | /api/user/{id} | Delete User Content | Required |
Following diagram shows the flow that we will implement for the User Registration
, User Login
, and Authenticate JWT
Processes.
https://www.getpostman.com/collections/1f14b750916ed2fefd28
Request :
-
Method :
POST
-
Endpoint :
/api/auth/signup
-
Header :
- Content-Type :
application/json
- Accept :
application/json
- Content-Type :
-
Body :
{ "email": "string", "username": "string", "password": "string, hash" }
-
Response :
{ "code": "number", "message": "string", "user": { "id": "string", "email": "string", "username": "string", "createdAt": "date-string" } }
Request :
-
Method :
POST
-
Endpoint :
/api/auth/signin
-
Header :
- Content-Type :
application/json
- Accept :
application/json
- Content-Type :
-
Body :
{ "username": "string", "password": "string, hash" }
-
Response :
{ "code": "number", "message": "string", "user": { "id": "string", "email": "string", "username": "string", "createdAt": "date-string" } }
Request :
-
Method :
GET
-
Endpoint :
/api/user/list
-
Header :
- Content-Type :
application/json
- Accept :
application/json
- x-auth-token :
string
- Content-Type :
-
Response :
{ "code": "number", "message": "string", "user": [ { "id": "string", "email": "string", "username": "string", "createdAt": "date-string" }, { "id": "string", "email": "string", "username": "string", "createdAt": "date-string" } ] }
Request :
-
Method :
GET
-
Endpoint :
/api/user/find
-
Query :
- id :
string
- id :
-
Header :
- Content-Type :
application/json
- Accept :
application/json
- x-auth-token :
string
- Content-Type :
-
Response :
{ "code": "number", "message": "string", "user": { "id": "string", "email": "string", "username": "string", "createdAt": "date-string" } }
Request :
-
Method :
PUT / PATCH
-
Endpoint :
/api/user/{id}
-
Header :
- Content-Type :
application/json
- Accept :
application/json
- x-auth-token :
string
- Content-Type :
-
Body :
{ "email": "string", "username": "string", "password": "string, hash" }
-
Response :
{ "code": "number", "message": "string" }
Request :
-
Method :
DELETE
-
Endpoint :
/api/user/{id}
-
Header :
- Content-Type :
application/json
- Accept :
application/json
- x-auth-token :
string
- Content-Type :
-
Response :
{ "code": "number", "message": "string" }