Posts

Showing posts from November, 2022

Async JS Codevolution

Image
               Why async How ? Tradional Methdo of Js setTimeout To Clear a timeout use It will ensure that greet function will not run after 2 sec duration Remember to clear the interval esle it will run forever   2 cont... funtion will run  only after call stack is free   CALLBACKS Rewriting the code as per their names Types of Call Back Sycnhronus Callback (Same as bove) Nothing to fancy about synchronus callback Async Callback Here, the magic is there so learn it ,revise it In eg 1 setTime out is hOF and greet() is callback funtion eg 2: addEventListener is HOF and the fn attaxched to event handler is the callback as it will only be excute after it isbeen  clicked This becomes extremely unreadble so promises has been introduced Promise ' WEcan pass value to resolve and rejected if we want to add extra bit of info The value is automactially fetched and it can be accessed More details Bothe means same Howevver, 3. Chaining Pr...

MongoDB Express Nodes

Image
 Create Database Connection     We can't import everywhere mongoConnect as it is a kamur process so to avoid it we add it globally 1) Add ver name _db 2) Assign it to client.db() 3) create a fn and export it Now to add db we need to just add above function and keep server like this To insert on element in database Since we have already got the date we can directly add this to add all elemnet We will instead return it so we can use than in controller  Now to fetch the products Things to note 1) find() provides a cursor which go one by one and if there are miillion of product it will go like that 2) to array converts those product in a list 3) dont use toFind() if u have million of products...instead use pagination Fethcing a single product 1) Find the product using find() method and use the id to get that specific product. 2) However,Mongodb cursor is unaware that I only want to find a single product so it will keep on goin down 3) To stop this use next() and then But...