you have seen app.get right inside it we write a url like /insta and after that we write a callback. basically what we are doing is that we are mentioning that if it hit that url do this and the work is define in the call back
#the callback has it own param which is req and res . and we can write like res.send("tenz"). so now whenever a /insta url is hit the respond tenz is send. now the middleware comes simply we can say it as a checker. whether it fullfill some requirement like whether he is login first now when the url is hit it check the login first then it compute the response
the callback have mainly four param that are (err,req,res,next) next is a flag mostly used in middelware, when the middleware is done it pass a flag saying i am done now go to next middleware or any
these days multer is more prefered
what we will do is take image from user and store it in local for temporarly using multer and then using cloudinary we upload it in cloudinary, we can directly do it but it is not a good practice
when going just met me once( jab jarahe ho to mil ke jana)
the http and the https difference is that http when send data and recieve data it is the same like hello to hello but in https -a layer is introduce where the encrpytion is done
url uri urn all are like same url is the uniform resource locator, the uri is the identifier and urn is the name
the header are used in caching, auth and state management
- accept: application/json # which type is accepted
- user-agent //info of from where the data is coming like browser ,postman
- authorization: bearer (here jwt token is wrote)
- content-type // like images pdf
- Cookie: //like seting the cokkies
basic operation that is used to interact with the server
1.GET - retrieve a resource(taking resource) 2.HEAD - only header no message body 3.OPTION - what operation are avialable 4.TRACE - mainly in debugging / loopback test(get same data) 5.DELETE -remove resource 6.PUT - replace resource 7.POST - interact with the resource(mostly add) like add new user (mostly used method) 8.PATCH - particular part is change rest are same
1** informational 2** sucess 3** redirection 4** client error 5** server error
100 continue 102 processing 200 ok 201 created 202 accepted 307 temporary redirect 308 permanent redirect 400 bad request 401 unauthroizied 402 payment required 404 not found 500 internal server error 504 gateway time out
here the .some is usefull to find whether true or not for many files
if u have it u have the access to the features that need authentication that are only explicit to the person now when it get expire then refresh token comes in place(save both in user and database) user validation is done with access token but u dont have to put password always if u have the refresh token. u just have to hit a endpoint(if the refresh token and at the endpoint and urs match then it will give you a new access token)
main thing is that user dont have to give email and password always access token is usually short live (like 1 hr)
refresh token is store in database access is not
so to refresh the token we have to creata end point to do so
#database usually when we try to write query related to database we use await and async as database is in other continent(model)
pipeline is basically like chaining (stages) like each stage the output of each stage will be the new starting point of the next stage , for example you start with a 100 dataset,in stage1 you did a set operation and the res data was 50 dataset now the next stage will perform on that 50 dataset not the initial one
- written as //in an array. each object act as the stage db.order.aggregate([ //stage1 the first stage is usally the match operation { $match:{size:'medium'} }, //stage2 { $group:{_id="$name", totalquantity:{ $sum:"$quantity" }} } ])