CRUD Back-End API With NodeJS, ExpressJS, MongooseJS, MongoDB Node_modules in Use -> mongoose, validator, bcryptjs, jwt[jsonWebTokens], Sharp,
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
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]
1-> Run The mongoDB Server 2-> Connect it with either MongoDB Atlas Or Robo3T
-> 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 :-
*(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.
*(Note) authToken is the variable which we set up in [1] Step
As Soon as you SignUp you will get an email regarding signup.
http://localhost:3000/users/PasteIDoFUserHere/avatars
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)"