Task-Manager-API
CRUD Back-End API With NodeJS, ExpressJS, MongooseJS, MongoDB Node_modules in Use -> mongoose, validator, bcryptjs, jwt[jsonWebTokens], Sharp,
Installation
Use the commannd to install all node_modules as well as dependencies
npm install
We have declared Enviroment variables in config>dev.env
PORT=3000
SENDGRID_API_KEY=PasteSendGRIDApi Here(SignUp for their service)[We will use this to email user during signup as well as termination of account]
MONGODB_URL=mongodb://127.0.0.1:27017/task-manager-api
JWT_SECRET=YourSecretKeyHere
Usage
run the following command
npm run dev
This Command is being declared in package.json file as following
"scripts": {
"start": "node src/index.js",
"dev": "env-cmd ./config/dev.env nodemon src/index.js"
},
The dev command with [env-cmd ./config/dev.env] will ensure running and setting the enviroment variable , which you can further use in your program by [process.env.ENV_VAR_NAME]
Working
Prerequisite
1-> Run The mongoDB Server 2-> Connect it with either MongoDB Atlas Or Robo3T
Configuration For POSTMAN
-> Add Following Test in Create User as Well as Login Request [Create User Request]
if(pm.response.code === 201) {
pm.environment.set('authToken', pm.response.json().token)
}
[Login User Request]
if(pm.response.code === 200) {
pm.environment.set('authToken', pm.response.json().token)
}
In POSTMAN > Settings Icon[Manage Enviroment] > Click Add & Add the following :-
[1.1] When Testing on Local Enviroment
*(NOTE), DO NOT ASSIGN VALUE TO AUTH TOKEN, It will be assigned by our test Script.
*(NOTE), DO NOT ASSIGN VALUE TO AUTH TOKEN, It will be assigned by our test Script.
[1.2] When Testing On Production Enviroment
[2] Project > Setting > Edit
[3] Choose Type > Bearer Token > Set Token Value > {{authToken}}
*(Note) authToken is the variable which we set up in [1] Step
Creating User
As Soon as you SignUp you will get an email regarding signup.
Login User
Logout Current Session User
Logout Every User Ever Logged in Anywhere on Earth :p
Delete User
Read Profile
Create Task
Read Single Task By ID
Read Tasks In Descending Order
Read Tasks In Ascending Order
Read Task In Desc Order , Limit only 2
Read Task In Desc Order, Limit only 2 , Ski the first record from Data
Update Details of User
Update Task By It's ID
Delete a Task By It's ID
Upload a Profile Photograph For Current User
View The Profile Photograph For Current User
http://localhost:3000/users/PasteIDoFUserHere/avatars
Working with MongoDB , In Production
https://medium.com/@rehaancool796/how-to-setup-mongodb-production-database-12-steps-b54159dc17e6 You can Read this article on medium, which I wrote for people who want to try this project :) When Uploading This project to heroku I have set enviroment variables with the help of the following command below -
[heroku config:set key=value key1=value key2=value]
heroku config:set SENDGRID_API_KEY=value JWT_SECRET=YourSecretKeyHere MONGODB_URL="The url you got from the atlas website(read medium article for more)"