SonoJsistheJavaScriptruntimeenvironmentthatallowsyoutoexerciseJavaScriptcodeoutsideof a browsersuchasOn a ServerandExpressis a WebapplicationframeworkforKnowJs.
Itallowsustoeasilycreate a Webserver, andthenMongo D.
B isthedocumentbasedopensourcedatabase.
SoinourappwillbestoringourdatainMongo D.
B.
Andthenfinally, thefrontendisreact, whichis a jobscriptfrontandlibraryforbuildinguserinterfacesandthen, finally, atthebottom.
TherewewillbeusingMongoose, whichis a simple, schemabasedsolutiontomodelapplicationdata.
Basically, itmakesiteasiertouseMongo D B inKnowJs.
Solet's reviewsomedatabaseconcepts.
We'regonnajustreviewsometerminology.
Sowhat?
A lotofpeopleareusedtoourtabularorrelationaldatabases, sowethinkofthingslikedatabases, tables, roseandstufflikethat.
SoMongo D.
B hassimilarconceptsthatusedifferentterms, so I justwantitcanmakeeveryoneawareofthoseterms.
Andjustsoyouknow, I'm doingthisallin a slideshowrightnow, butin a littlebitwillactuallybeontheactualwebsitesoyoucanseewhereallthisisontheactualwebsite.
Butfrom a securitystandpoint, weneedtosetup I P WhiteListaddressesand a databaseuser.
Soforthisproject, sinceit's justgoingtobehostedonlocally, wecanaddyourcurrent I P addressfortheWhiteList I P addressandThenyoucancreateanyusernameandpasswordfortheMongo D B user, sonowwecangetourconnectioninformation.
Thereare a fewdifferentwaysthatweprovideinformationtoconnecttoMongo D B AtlasthroughtheMongol D B shell, whichis a commandlineinterfacewiththeApplicationConnectionString, whichiswhatwe'llbeusingtodayandthroughMongo D B Compass, whichis a gooeytoolforinteractingwithdatastoredinMongo D.
B.
Sothen, afteryouclick, theconnectorapplicationwillbetakentothescreenontherighthere, andwe'reprovidedinformationongetting a connectionstringandthensomeconnectionexamplesfordifferentlanguages.
Soalso, wealreadydiscussedMongoose, whichmakesinteractingwithmongo D B throughnode.jssimpler, andthelastoneisnodot m v, whichlowsloadsenvironmentvariablesfrom a dottyenvyfileintoprocessdot m b.
Thismakesdevelopmentsimpler.
Soinsteadofstudyingenvironmentvariablesonourdevelopmentmachine, theycouldbestoredin a file.
We'llcreate a dot N V filelater, sowe'llinstallonefinalpackageglobally, So I'lldoMPMinstall G forgloballyandnodemon.
Soknownmonmakesdevelopmenteasier.
It's a toolthathelpsdevelopknowJsbasedapplicationsbyautomaticallyrestartingthenoteapplicationwhenfileswhenfilechangesinthedirectoryaredetective.
Solet's see.
Lookslikewehavesomesortofair.
I wonderwhat a Oh I shoulddo a pseudowheneveryou'regoingtoinstallsomethinggloballywilldoStudioinstall G Nowouldmom.
Sothisisthecore's middleware, andthisisgoingtoallowustoparseJasonbecauseourserverisgoingtobe a sendingandreceivingJasonandthenyoucanseethislineHereiswhatstartstheserver.
Itstartslisteningon a certainport.
Sooncewehavethat, I cansavethis, and I canstarttheserver.
Sointheserverfolder, firstofall, I willsavethis, andthenwe'rejustHehadairdownherebecausewedon't havethisenvironmentalvariableyet.
So I'm goingtogointomyBackendfolderandcreate a newfilecalleddot E N V.
Sonowweneedtogettheyoureyeortheconnectionstringfrommongo D B Atlas.
Soletmegoovertothat.
Um, here's mom, JudyBeeAtlasand I alreadyhavetheum, theclusterofcreated.
Soif I createquickconnecthereconnect, you'reapttoyourapplicationand I'm goingtocopytheconnectionstring.
Sonow I cangobackovertomyfilehere, andwejusthavetocreatetheenvironmentalvariable.
Soremember, it's calledatlistsunderscore U R I.
Andthen I said, Whatisequaltoandnow I'm justgoingtopasteintheyoureyeconnectionhere.
Andonething I havetodo a TTEthebeginning.
You'llseethatthere's thispasswordhere.
Sohere I justactuallyhavetotypeinmypassword.
Sodon't tellanybodywhatmypasswordis, butit's I mean 123 forextrasecurity.
I alwayshavetheexactsamepasswordasmyusername.
No, that's nottrue.
Youshouldneverdothat.
Butinthiscase, that's what I'm doinghere.
SonowweshouldIf I savethisandthenif I restartmyserver, weshouldseemongo d bewritingtheConsulterminalmonger D B databaseconnectionestablishedsuccessfully.
So a lotofthisisgoingtolookthesameforanyMongooseschema.
Um, so I'm goingtosavethat, andthenwe'regoingtodotheexercisemodelsoyou'llseetheexercisemodelisgoingtolookalmostexactlythesamewithjust a fewchanges.
Zoomoutjust a littlebit.
EsoEverything's thesame.
Exceptthistime, insteadofonefield.
Wehavefourfieldsnowittakesuplessspacebecausethevalidationsareallonthesamelineasthefieldandwedon't have a CZmanyvalidationssoyoucanseewehaveusername, description, durationanddate.
Andinsidethatfolder, I'm goingtocreate a filecalledExercisesthatJsand a filecalledUsersThatJsSowe'llcomebacktothosefilesfirstwilltelltheservertousethefileswejustcreated.
Soifit's now, it's ifit's therouteyouare, l slashexercisesslashattheendtogetrequest, thenwe'regonnarunthismongoosecommandexercisethatfind, ThenafterwefindalltheexercisesfromthedatabasewilltakethoseexercisesandthenreturnthemasJasonorelsethere's anear.
Sothispartis a littledifferent, butit's it's basicallythesameasbefore.
Ifwehaveexercises, slashadandit's a postrequest, theninsteadofjusthaving a usernameandthebody, we'regonnahavetheusername, lovedescription, thedurationandthedate, andwe'llsignittothesevariablesandyoucanseethatwe'reconvertingthedurationto a numberandwe'reconvertingthedateto a date.
Theyhad a type, andthenwejustcreatenewexercise, usingallofthesevariablesthatwegotuphere.
Andthenwesavetheexercise, andafteritsavedthat, thenit's a promisewe'regoingtoreturn.
TheJasonexerciseadded, We'lladdsomeor a P I m pointsoon, butfirst, let's testtheserver a p.
I willbeusing a toolcalledInsomniatotestthe A P.
I.
Anotherpopulartoolforthispurposeispostman.
Theybothdoprettymuchthesamething.
Soonceyougetintoinsomniaoryoucouldusepostmanwillcreate a newpostrequestusingJason.
So I'lldo a postrequestandallthisstuffcouldbechangedonthenextscreenhere.
Sowehavethispostrequestandwe'llgotothe U R L A C T T p colonslashlastlocalhost 5000 slashusersslashAB.
Nowweshouldstillhaveourserverrunning.
Sointhebody, I willselectJasonandwe'regoingtosend a username.
We'regonnaadd a username.
So I'm goingtocreatethisJasonobjecthere, useyournameboat.
Andif I clickposthereOh, I mean, I'm a clicksend, anditsays, useradded, Sonowwecansendtheygetrequesttoget a listoftheusersback.
Sofirst, letmejustaddanotheruser.
So I'lljustdoQuincyhereandsendthatanduseradded, Sonowwecando a getrequesttogetthelistofusersback.
Soinsteadofusersslashad, it'lljustbeuserslashwithouttheadattheend, I'llchangethisposttoget, andwedon't needthisyearand I'lljustclicksendandyoucanseeourusersherewithsomeadditionalinformationheresoyoucanseemongo d beautomaticallycreatedthisobject I d.
Andthenweneed a descriptionandwe'llsetthattorunandthenforduration.
Andthedurationisinminutes, whichyou'llseeoncewecreateourfrontendwilldoinnineminutesandfor a date.
Um, I'm actuallyjustgoingtocopythisdatefromoverhere, Uh, oncewecreate a frontandyou'llneverhavetoactuallyenter a datebecauseyou'llbejustselecting a datefrom a dropdownmenu.
Butsincewe'reentering a directlyintothedatabasewiththiscopyandpaste, soif I clicksend, weshouldseeOpecannotgetbecause I forgottochangethisto a postrequest.
Ourserverdidnothaveanything.
Forgetrequesttothat.
You'reallbutlet's try a postrequest.
Okay, exerciseandID.
Well, let's addonemoreexercise, whichisgoingtobe a bikeride.
Sameusername.
Andthistimeitwasfor 30 minutes.
And I'llchangethistoo.
Um, let's see, 27.
Andif I justsendthatwejustaddedanotherexercisesowecando a getrequestIf I justslashed.
I didn't doanythingwithit, butyoucanseeoverherewehaveourtwoexercises.
Weadded.
SoyournameBoDescription.
Rundurationnine.
Wehavethedate.
Samedownhere.
Wehave a bikeride, andifwegoovertomongo D B atlasandthen I'm justgonnaclick, refresh, goingtoexercisesandyoucanseeHere's thattwoexercisesweaddedsoandrightfromhere, youcanactuallydosomeediting.
Likeif I wanttosay?
Actually, thiswas, uh, 60 minutesthat I canupdate.
Thatusernamebecauseit's goingtohavethisrouteneedstoreceive a a Jasonobjectthat's goingtocreatethat's goingtocontain a username, a description, a durationand a date, justlikewhenyou'readding a new a newexercise.
Sothisiswhere a basicjobscriptfilethatloadsandyoucanseeit's goingtoeloadReact, react, Tom, theindexthatCSSwe'renotwritinganycustomCSSsowecangetridofthatimportingapp.
Andthenwehavespecialclasses, just a styleusingbootstrapstylessoyoucanalwaysjustcheckoutthebootstrapdocumentationifyouwanttolearnmoreaboutthestylesyoucandowiththat.