CRUD Operation and JWT token
Published: 2021-12-24 13:35:16

**CRUD OPERATION**
The heart of a dynamic application is a database. Whether the application is e-commerce or social network or even a to-do app on your phone the data needs to change over time. For example, if you run an e-commerce site you’d want to search the products, update stock counts, create new orders or add new products in your database and maybe remove the unnecessary products from the database. The site is dynamic because the state changes all the time.
CRUD is an acronym that refers to the four main operations that you’d want to perform on data in a database.
The four main operations you’d do with your database are following:
-        You’d want to add or create data to a database.
-        You’d want to read the data. Reading includes searching and filtering the results.
-        You’d want to update or edit the data.
-        Finally, you’d want to delete or remove the data from the database.
These four operations Create, Read, Update, Delete are shorted in the acronym CRUD.

**JWT**
JWT is just used for authorization, not authentication. They are slightly different. With authentication, we are taking a username and a password to make sure that that user name and password are correct. It’s like logging a user in.
But authorization is making sure that the user that sends a request to your server is the same user that logged in during the authentication process. It’s authorized that this user has access to this particular system.
The authorization process is normally done by using a session. So, for example, you have a session Id that you send down in the cookies of the browser and then every time the client makes you request, they send the session-id up to the server and the server checks its memory and says ok what user has that session id, in this it finds the user and then it does the authorization to make sure that the user has access of this particular system.
But JWT instead of using these cookies it users a JSON web token, which is what JWT stands for to do the authorization
The main difference between these two is that in a normal process using session the information about the user is stored on the server. So, the server has to do a lookup to find the user based on the session ID.
But with JWT information is stored in the actual token which means it’s stored on the client-side. the server doesn’t have to remember anything. That is great because you can use the same JSON web token (JWT) across the multiple servers that you run without having any problems.

**MONGOOSE**
 
Mongoose is an Object Data Modeling(ODM) library for MongoDB and node.js providing a higher level of abstraction. It’s a bit relationship between express and node. Express is a layer of abstraction over node while mongoose is a larger abstraction over the regular MongoDB driver.
An object data modelling library is just a way for us to write JavaScript code that will then interact with a database. So we could just use a regular MongoDB driver to access our database and it would work just fine. But instead, we use mongoose because it gives us a lot more functionality allowing for faster and simpler development of our applications.
Some of the features mongooses gives us is schemas to model our data and relationship, easy data validation, simple query API, middleware etc.