YoucanseethatourpathshavechangedAndnowif I typenodeapnot J Yes, youcanseethatweget a helloworldfromnoteSoeitherwayisfineIfyouwanttousevisualstudiocodeanditsintegratedterminalyou'remorethanwelcometoIfyou'reusing a differenteditoranditdoesn't haveitsownintegratedterminal, you'remorethanwelcometousethecommand.
Promptthistutorial.
We'regonnabetalkingaboutnodemodulesallandnomoduleisisbasically a JavaScriptfile.
It's a waytoseparateconcernsforapplication.
So, forexample, let's saythat I haven't appdotJsfile.
Andinthisappthatjazzfile I havemath, a bunchof a P I requestanddatabasecallsinsteadofputtingthemallononefile.
So I'm gonnasayconsummateandit's gonnahavetoparametersandalwaysgonnadoisaddandreturnthemsonumboneplusnumbertwoNext.
What I wanttoendupdoingis I wanttoexposethisfunctiontotheoutsideworldbecauserightnow, if I hadcontrol s andif I wastotrytousedysfunction, so I'm justgoingtodeletethis.
Soif I wasjusttosaysomeoneplusoneandifweweretoactuallyrunthis, youcanseethatwegetanerrororsomeisnotdefined.
Soyoumightbesaying, Whyissomenotdefined?
I justtofindithere.
Well, I needtoexposethisfunctionfortheoutsideworldtouse, So I needtoletNo, no, thatthissomefunctionwithinmytutorialmoduleisavailabletobeused.
Soinordertodothator I needtodoistypemoduleexportsandpassitinsome.
Likesonowthatthisisavailabletobeused, I needtotellmyappdotJsfirewherethissomefunctionislocated.
Sowhat I candohereistheclearvariable.
So I'm justgonnasayconcerts, tutorial.
Andnow I'm justgonnausethewordrequire, andthenwe'regoingtogiveit a path.
NowthepathisdotFordslashed.
Sowheredid I getdotforitslashfromdotForwardslashmeansthatit's withinthesameexactpaththatthisfileiscurrentlyin.
WhereatdotJsSoif I wasthehitcontrol B, youcanseethat I that j s isonthesamelevelastutorialdotJsandthatthey'reinthesamefoldercalledKnowJstutorial.
Soif I hitcontrol, beagain, getridofthatandthen I passinthenameofthefilewhichisobviouslytutorialdotJs.
Soinordertodothat, that's actuallyadd a couplethings.
Firstthing I want a newlinerightafterthisquestionmarkhere.
So I'm justgonnasayforitslashAndsowhen I prompttheusertheusesinputinsteadoflininguprightnexttoitlikesoisgonnabeunderneath.
Allright, so I fixedthatproblem.
Nextthing I wanttodoisactuallytesttheuserinputtoseeifheactuallygottheanswer.
Correct.
Soinordertodothat, I'm justgoingtosayifuserinputandit's alwaysimportanttotrimtheuser's inputifyoueveracceptanythingfrom a userjusttogetridofthetrailingwhitespaceandwe'rejustgoingtosayiftheuser's inputisequaltoeanswer, Soiftheyanswerthemathquestioncorrectly, I wannaclosetheapplicationSo I couldsayourOh, thatclose.
Andhereandnowif I wastosavethisandnowexecutetheprogram.
So I'm justgonnawritenodeappisgoingtosaywhatis 10 plusfourand I'm goingtoanswerwith 14 andyoucouldseethatweanswereditcorrectlyandthereforeourapplicationclosed.
Now, when I wanttodoisactuallyadd a listenertotheclothesevent.
So, inordertodothat, let's createan L statementwithinourquestionmethodhere.
So I'm justgoingtosayelseandwhat I wanttodobasicallyisreprompttheuser.
So I'm justgonnasay, areallthatpromptthatsetpromptandSepppromptisbasicallygoingtotakenargumentofstringandisgoingtoasktheuserbasicallywhatyouwanttoknow?
So I'm goingtosaytotheuserIncorrectresponse.
Pleasetryagain.
Um, let's add a newlinehereandnow, inordertousetheprom, actuallyhavetocallit.
Soif I wastosaycontrolbeagainand I'm justgonnagotoeatdotJsAndwithinthiselsestatement, let's putallthiscodewithinhereandnow I'm gonnasay F s aboutreadfileandwithinhere, thefirstargument, muchliketherightfilemethod, isgonnabethenameofthefilethatyouwanttoread.
So I'm justgoingtosayexamplethat t x t Thesecondargumentisgonnabetheencodingtype.
Now I'm gonnaleavethisblankbecause I wanttoshowyouguyswhathappenswhenyoudon't leaveandencodingtypeandinthethirdargumentisgonnatake a callbackfunction.
Nowwhat I wanttodoislet's saythatwhen I createdthisexampledot t x t followthat.
I reallydidn't meantocallitexampledot t x t Let's say I wantedtocallitahexampleto, forinstanceWell, I couldusetherenamethatthingso I coulddosomethinglikethis.
I cansay f s dotrenameandrenameisgonnatakeinthreearguments.
Thefirstargumentisgonnabeexamplethat t x t andthat's gonnabethenameofthefilethatwewanttorename.
So I'm justgonnasaysomedatabeingupended, andthethirdargumentisgonnabethecallbackfunction.
Andthisisgoingtohaveanerroras a parameterpastthisandAndwe'regoingtosayiferrorrentedouttotheconsulOtherwise, we'regonnaprintoutthatthesuccessfully a pendantdatatothefiresosuccessfullyupendeddatatofile.
I'm justgonnamovethisoversoyoucansee.
Andnow, if I savethisandexecutethissonodapandseesuccessfully a pendantdatatofile.
Solet's actuallytake a lookatourfileandyoucanseethatourfilehasbeenchanged.
Sobeforewehad, thisisanexample.
AndthenwehavepennedIt's ondatatotheendofthefile.
Andthelastmethodthat I wanttocoverwithinthistutorialishowdo I delete a fire?
So, forexample, wedidallofthisandlet's saythat I'vehadenoughwiththiswhile I justwantitgone.
Solet's justcommentthisoutandthisisgonnabethefinalmethodthat I goover.
So I'm justgonnaheadcontrolassgodownherenodeapp, andyoucanseethatsays, successfullycreatedfiledownhere.
Sonowif I hitControl B and I'm gonnagouphereandthenhitcontrol B, youcanseethatwehaveournewlycreatedtutorialfolderandwithinherewehaveourexamplethat t x t Soifwegoinhere, youcouldsee, ithasthedataof 12 andthree.
Now, what I wanttoshowyouishowwould I delete a folderthathas a firewithinit?
Soyoumightbesaying, if I justgobackhere, hitcontrol, bethatCan I justuse F s dotremovedirectoryinordertodothis?
Well, I amactuallyjustgonnacommentonotherfelt.
Andwhatwillenduphappeningif I usetheremovedirectoryfunctionisthatisthat I'llgetanerror.
Andthereasonforthatisbecauseif I usetheremovedirectoryfunction, ithastobeusedon a directoryorfolderthatisempty.
Sonow I'm justgonnasay, fourletfileoffilesandthenwithinhere, wecanstartdeletingeachfileindividually, so I couldsay f s theunlinked, andthenwe'regoingtogiveitthefilename.
Sobasicallyeverytime a dataeventoccurs, I amgetting a chunkofthefire.
I'm notattemptingtoreadtheentirefileatonce, andthereforethebuffersizecouldbe a lotsmaller, asopposedtothereedfoundmethod, whichuses a fullbufferwhichneedstobebigenoughtoloadtheentirefileatonceandthenservestreamsallowfor a smallerbuffersize, whichismemoryefficientandfordatatobereadandwrittenandchunks.
Andthistutorial, we'regonnabegoingoverpipes.
Nowwhat a pipeallowsustodoisbasic
Hey, what's up, guys?
Subtitles and vocabulary
Click the word to look it upClick the word to find further inforamtion about it