We'regonnabeusing a databasecone, mongo, D B, Andforourclientside, we'regonnabeusingJakeRiri, theFetch A P I andBootstrapped, andyoushouldknow a littlebitaboutHTML.
Andlastbutnotleastforourserversideandclientside.
We'regonnabeusing a programminglanguagecalledJavascript.
Sonowlet's actuallytake a lookattheapplicationthatwe'regonnabebuildingwithinthistutorial.
So I'm justgonnasayconstantappisequaltoexpressandlet's callitnowwe'regonnatellourexpressapplicationtousethebodypartsinmodule, andwe'regonnabeparsingJasonDatasentfromtheclients I totheservicesideusingthebodyportsmodule.
Next, let's requireourpathmodule.
Afterthat, let's bringinourdatabasestuff.
So I'm justgonnasayconsthe D isequaltorequirebaby.
Andlastbutnotleast, we'regonnahaveonemorevariablehere, andwe'regonnacallitcollection, andwe'regonnacallit a collectiontodosowe'regonnahave a database, andthatdatabaseisgonnahave a collectionwithinitcalledtodo, andthat's gonnaholdourtwoDUIs.
Sonowlet's headovertoourDVDdotJsfile.
Andnowwe'rejustgonnaimportarmmongo D B drivers.
I'm justgonnasayconsmongoclientisgonnabeequaltorequiremongo D.
B.
Andwe'regonnarequirethemongoclientfromit.
We'realsogonnarequiretheobject i d fromthemongo D B module.
So I'm justgonnasayconsobject I d gonnabeequaltorequiremongo d b dotobject.
I d.
Next, let's giveourdatabaseofnames, so I'm justgonnasayconsbebenameisgonnabeequalto, and I'm justgonnacallitcriedmongo D B.
Afterthat, we'regonnacodeareyouarewell, Andthisisbasicallythedefaultlocationofwhereyourmongo D B wouldbelocatedonyourlocalmachine.
So I'm justgonnatightmongo d b localhost 27 0 17 Andthelastconfigurationthatwe'regonnagiveourdatabaseistheoptionsthatwecouldpassin.
So I'm justgonnasaymongooptionsandwe'regonnabeusingthenew U R L Par, sir.
Let's setthatthetruth.
Sonowlet's actuallygivethis a state.
Sowe'regonnabeusingthisdebate.
I JsfiletoactuallycreatetheconnectionbetweenknowJsandArmando D B Server.
SothisisgoingtosignifythatHey, wedon't have a databaseyet.
Next, let's actuallywriteourconnectmethod, so I'm justgonnasayconcertconnectisgonnabeequalandwe'regonnapasson a callback, andwe'rejustgoingtosaythefollowingifstatethat d B Soifthereis a databaseconnection, we'rejustgonnacalltocallbackifthereisn't a databaseconnection, we'regonnausethemongoclienttoconnecttothedatabase.
Andthisisthefunctionthatwejustcreatedan R D B file.
We'regonnapassin a callback, andwe'regonnasay, ifera, we'regonnaconsulaboutlogunabletoconnecttodatabase, andwe'regonnaterminatetheapplicationandweshouldprobablywrapthiswithincurlybraces.
Andifwewereabletoconnecttothedatabasesuccessfullyweregoingtosayelseafter I listenandyoucouldusewhateverportthatyouwant, I'm justgonnausePort 3000 andwe'regonnapassin a callback, andwe'rejustgoingtosay, connectedto a database.
APlisteningonCourt 3000.
Sonow, if I wastosavethis, that's put a semicolonhereandthensaveit.
Let's goopenup a terminal, sealusagainin a typednoteapp, andyoucouldseethatwegotnoerror.
Sothatmeanswebypassedthisairstatementandweexecutedour l statement.
Thefirstgetrouteisactuallygoingtosun a staticHTMLfilestotheuser, andthesecondgetrouteisactuallygoingtoquerythedatabaseforordertoduesifanarttodocollectionandit's gonnareturnthattotheuser.
Solet's actuallygetstarted.
Encodingthis.
So I'm justgonnagodownhere, I'm gonnasayafterYeah, andwe'regonnagiveit a pathoffourslashgiveitthisfunction, andthenwhenwegetdownhere, allwe'regonnadoissend a staticHTMLfile, so I'm justgonnasayrezdotsandfile.
Andhere's whereourPATHmodulecomesinhandydotJoinNow, thisfiledoesn't exactlyexistyet, butwe'regonnabecreatingthiswithin a futuretutorial.
Sonowlet's actuallyheadonovertooursecondatdotGet, and I'm justgonnacallthisapp.
Thatand I'm gonnacallthis.
GettwoDUIs, thenhere, we'regonnapassinourfunction, ourrequestsobjectourresponseobject, Andwithinhere, I'm goingtosay D b getTB.
Solet's headbacktovisualstobe a codegonnahitcontrol.
C Canceloutofthat.
Let's startouttheMongoshow.
Andnow I'm justgonnagobackuphere, Control B.
Let's findoutwhatwenamedourdatabase.
Sowenameditcrowdmongo D.
B so I'm justgonnasayusecriedmongo d b I'm gonnasay d b dotAndlet's gobacktoappthat j s andseewhatwenamedourcollectiontodo I'm justgonnasaytododotinsertandwe'regonnainsert a coupleoftodoso I'm justgonnasaytodoand I'm goingtosaycleanroomSolet's insertthatandlet's insertclean I don't knowGarage.
Solet's answerthat.
Allright, solet's canceloutofthatnoteapp.
Let's waitforourexpressapplicationtobootupand a workroom.
Sonow I'm justgonnasayelsesoifeverythingwentwell, we'regonnabesendingthatdatabacktotheuserandJasonformat, so I'm justgonnasayresult.
Now, let's add a semicolonhere, andlet's justdoublecheckthisandallthislooksgood.
Solet's actuallytestthisout.
So I'm gonnaopenuptheterminal, clear a terminalnodeapp.
Let's startupourapplication.
We'regoingtogotopostmen, andyoucanseeherethat I alreadyhavethissetup.
SotheeuroislocalhostPort 3000.
Thisisthe I d ofoneofdocumentsthat I havecurrentlywe'remaking a putrequest.
We'resendingbackJasondatahere, soyoucouldseehere.
Andthisisthedatathatwe'resendingback.
Andwecanmakethiswhateveryouwant.
Solet's justchangethis, too.
Uh, cleansomethingfortutorial.
Allright, sothisisgonnabeourtodo, and I'm gonnagohereandmake a request, so I'm justgonnahitsend, andyoucanseethatwegetanerrorandrightaway I alreadyknowwhat's goingon.
Sowhenwepassedinourtodo, thisis a stringwewantanobject.
Let's headovertopostmanandtoseethatwehaveourlocalwholesport 3000 herewiththeFordslashyou, Earl, we'remaking a postrequestandthisis a JasonobjectthatRhysendingbacktotheserver.
Solet's saythatwewant a post.
Ah, cleansomething.
Sothisis a todothatwewanttoinsertwithinourtodocollection.
Weonlyneedoneofthese, so I'm justgonnadeletethe 2nd 1 Now, let's justscrollovertotheright a bitandwe'regonnachangesomeofthisstuff, Butwe'regonnachangetheexampleabletotodo, andwe'regonnagivean I d.
Attributestoourinputfield.
Butwe'rejustgonnachangethisfromformgroupexampleandputtwotodouserinput, andwe'regonnachangetheplaceholdertosaytodonext, weactuallyhavetocreate a buttonsothattheusercanactuallysubmit, andwe'regonnagiveit a classofprimary, andthat's actuallycalled a buttoncreate.
Sowhentheuseractuallysubmit, we'regonnapreventthedefaultactionthattakesplacebecausewewannamake a restfulcalltoourserver a p I.
Now, let's gobackdownhere.
Sonextwe'regonnacoatseveralhelperfunctions, so I'm justgoingtosay, constantresettwoDUIsandputandthisisgoingtoresetthattodouserinputfield.
Next, we'regonnacreate a functioncalledbuildideas, andthisisgonnabuildunique i d.
S togivetoourHTMLelement.
Andit's gonnatakein a tododocumentandwe'rejustgonnareturnanobjectwithour i d.
So I'm justgonnasay, edit I D andeditideaisgonnabeattachedtooureditbuttonsowecanattach a clickeventtothateditbutton, andyoucouldseethatwe'retakingadvantageoftheprimarykeythatwegetfromourtododocumenttomakeitunique.
Next, we'regonnacodedally I D anddeleteideaisgonnabeattachedtoourdeletebuttonsthatwecouldattach a clickeventtoourdeleteBunin.
So I'm justgonnasay, butinhithecourtsofbutton, we'regoingtogiveit a classofsecondary, andwe'regonnagiveitanattributesofthe i D thatwecreateit, andthebuttonisjustgoingtosaynowthatwehaveoureditbuttonlet's copythis.
Let's actuallyupendeachoftheselistitemstoourown, ordered a list, So I'm justgonnasay, display a penandwe'regonnacallthebuildtemplatemethodthatwejustcreatedandwe'regonnapassinourtodoandour i.
Sowecalledit a getmethodnextweekaccordedthenmethod, andwe'regonnaget a responsebackfromtheserver.
And I'm justgonnasay, returnresponsethatJasonandthisisgonnaparsetheJasonforusbutthisisgoingtoreturn a promisewhenyoureturn a promisewecouldchainthatpromise.
I'm justgonnacallit, thenmetthereOnceagain s inourdata.
So I'm justgonnasay, fetch, we'regonnauseourendpointofforwardslashThenextargumentisgonnabeouroptions.
Sothefirstoptioniswe'repostingdatabacktodeserveer, I'm justgonnasay, post a secondpropertyisgonnabethebodywhatwe'resendingbacktothedatabase, so I'm justgoingtosayJason, notstring.
So I'm justgonnahitrefreshtoseeifitactuallyworked.
Andyoucouldseethatourdataispersisting.
Sothat's thebasicsofusingthefetch a p I toposttodeserve, erwelcometopartnineofbuildingourcrowdapplicationfromscratch.
Sointhistutorial, we'regoingtobemaking a httpdeleterequestusingthefetch a p i ontheprevioustutorials, youcouldseethatwecaughtit, areabouttheleaguerouteandisusing a ropeparameter.
Well, now, fromhere, I'm justgonnasayconsbelievetodoandit's gonnatakeinthreeparameters, Isgonnatake a todo, isgoingtotakethelistitem I d.
Andit's gonnatakethedelete i d.
Nowtodoisthedocumentthatwewanttobelievelistitem i d istheideaofthelistelementwithinourownorderedlistthatwewanttodeleteandthedeleteideasthe i d thatwe'vegiventoourdelete.
Butnowlet's actuallycodethisout.
First, weneedtogetourdeletebutton.
So I'm justgonnasay, theleftelite, butinisequaltothisnextLet's justlikeat a clickeventtoourdeletebutton.
So I'm justgonnacomedownherelatebutindotclickandwe'regonnapassinourbutCandlerandwithinhere.
Let's actuallycallourdeleterouteusingtofetch a P I.
So I'm justgonnasayfetchandwe'regonnapassinourroutenext.
Let's actuallypassingouroptions.
Sowe'reactuallymaking a deleterequest.
So I'm justgonnasaymethodandwe'regonnapassintheleaf.
If I thisisgonnacomeforourJavaScriptobjectintoJasonforusand I'm justgonnasaytodoandwe'regoingtogettheusersandputWell, nowthatwehaveouroptionssetup, let's calleditdonemethodtoexecutethisfetchrequesthere, we'regoingtogetourresponsefromtheserver.
Now, we'regonnareturnthatresponse, andwe'regonnacall a functioncalledJason.
NotthisresponsethatJasonisgoingtoreturn a promise.
So I'm justgonnagodownhereand I'm gonnacallitthenandit's gonnagiveusourparseddataback.