rehaankhan1 / Task-Manager-API

CRUD Back-End API With NodeJS, ExpressJS, MongooseJS, MongoDB

Home Page:https://sheltered-beach-17031.herokuapp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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. 2

*(NOTE), DO NOT ASSIGN VALUE TO AUTH TOKEN, It will be assigned by our test Script.

[1.2] When Testing On Production Enviroment

as

[2] Project > Setting > Edit

111111

[3] Choose Type > Bearer Token > Set Token Value > {{authToken}}

22222222 *(Note) authToken is the variable which we set up in [1] Step

Creating User

3 As Soon as you SignUp you will get an email regarding signup.

Login User

4

Logout Current Session User

5

Logout Every User Ever Logged in Anywhere on Earth :p

6

Delete User

7

Read Profile

8

Create Task

9

Read Single Task By ID

11

Read Tasks In Descending Order

12

Read Tasks In Ascending Order

13

Read Task In Desc Order , Limit only 2

14

Read Task In Desc Order, Limit only 2 , Ski the first record from Data

15

Update Details of User

18

Update Task By It's ID

19

Delete a Task By It's ID

20

Upload a Profile Photograph For Current User

21

View The Profile Photograph For Current User

http://localhost:3000/users/PasteIDoFUserHere/avatars 22

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)"