This is a complete initial setup of APIs with authentication in node. Technology includes node, mongoose, express, JWT, passportjs. Download and use this app as initial setup of node apis and enhance it according to your requirements..
- node js
- mongo db
i) Clone or download project in your system
ii) Run "npm install" to install all modules defined in package json.
ii) Run app.js File using - "node app.js" OR just use nodemon if you have installed it on your system
URL: http://localhost:3000/users/register
Request Type: POST
Headers- Content-Type:application/json
Body Params: { "name":"Explo Shot", "email":"[email protected]", "password":"denkste?", "username":"test" }
Response:-
{ "success": true, "msg": "User Registered" }
URL: http://localhost:3000/users/authenticate
Request Type: POST
Headers- Content-Type:application/json
Body Params: { "password":"denkste?", "username":"test" }
Response:-
{ "success": true, "token": "JWT token string", "user": { "id": "59653c1fdcb0d5398830010a", "name": "test", "username": "darkLoLer", "email": "[email protected]" } }
- Get User Profile (A call to check if token verification working)
URL: http://localhost:3000/users/profile
Request Type: GET
Headers- Content-Type:application/json
Response:- { "msg": "hiii" }
Enhance the API by creating your own Controllers and models.