This is a simple Node.js server using Express, JWT with sqlite3.
With the route middleware to authenticate and check token.
Send request with token in session
, body
, param
or header
:
req.session.token
req.body.token
req.param('token')
req.headers['n-access-token']
- Nodejs
- Dependencies:
"array-unique": "~0.3.2", "body-parser": "~1.18.3", "cookie-parser": "~1.4.4", "cors": "~2.8.5", "deepmerge": "~3.2.0", "express": "~4.16.4", "ejs": "2.5.6", "express-session": "^1.11.3", "helmet": "^3.6.1", "moment": "^2.18.1", "fs": "0.0.1-security", "jsonwebtoken": "^8.5.1", "latinize": "~0.4.0", "md5": "^2.2.1", "morgan": "~1.9.1", "node-cron": "~2.0.3", "pug": "~2.0.3", "sequelize": "^5.3.1", "serve-favicon": "~2.5.0", "sqlite3": "^4.0.8", "yargs": "~13.2.2", "path": "^0.12.7", "request": "^2.81.0", "underscore": "^1.8.3"
npm i
Start the server in bash
node index.js
The server is running at http://localhost:4000/
Existing API:
Using POST with Content-Type: x-wwww-form-urlencoded
POST http://localhost:4000/api/login
Content-Type: x-wwww-form-urlencoded
username: nle
userpwd: 1234
or using GET:
GET
http://localhost:4000/api/login/nle/1234
Data retrieved:
{
"message": "success",
"token": "aaa.bbb.ccc",
"data": {
"id": 1,
"isActive": 1,
"useremail": "[email protected]",
"username": "nle",
"firstname": "Le",
"midname": "Quoc",
"givenname": "Nam",
"birthday": "",
"gender": 1,
"avatar": "avatar.jpg",
"phone": "1080",
"address": "Nha ko so - Pho ko ten",
"gps": null,
"created": "2019-05-02",
"updated": "2019-05-31",
"started": "2019-05-02",
"ended": null,
"dept_id": 1,
"metadata": null,
"deptName": "Developers"
}
}
GET
http://localhost:4000/api/me
Data retrieved:
{
"id": 1,
"isActive": 1,
"useremail": "[email protected]",
"username": "nle",
"firstname": "Le",
"midname": "Quoc",
"givenname": "Nam",
"birthday": "",
"gender": 1,
"avatar": "avatar.jpg",
"phone": "1080",
"address": "Nha ko so - Pho ko ten",
"gps": null,
"created": "2019-05-02",
"updated": "2019-05-31",
"started": "2019-05-02",
"ended": null,
"dept_id": 1,
"metadata": null,
"deptName": "Developers",
"iat": 1589277908,
"exp": 1589637908
}
GET
http://localhost:4000/api/people
GET
http://localhost:4000/api/logout
This repository is for teaching purpose at HUTECH in 2017.
Contact me for futher information:
- Le Quoc Nam
- [email protected] / [email protected]
- https://nready.net