Ifwetype n p m onit, Dash, whyinourcouncilhitEnter, thisisgoingtogiveus a boilerplatebasicpackagedotJason.
Andnowifwetype n p.
M i andallofourdifferentdependencies, wecaninstallourdependencies.
Sowe'regonnahaveexpresswe'regonnahavemongoose, andwe'regonnahave E J s Expressallowsustocreateourservermongoosesfor a databaseand e j s isforourdifferentviews.
Nextthingwecandoisinstallourdeaddependencies.
Sowe'llsay N p m I Dash, DashsaveDev.
AndinherewewanttoinstallNodeMonNownooneisgoingtoallowustoautomaticallyrefreshourwebpageeverysingletimewemake a changetoouractualfileshere.
AndinordertorunnodeMonwhichisgoingtocreate a simplescript, wejustcallitDeathStart.
Andinsideherewe'rejustgonnaputnodemonserverdotJs!
AndnowifwecreatedthatserverdotJsfileandwerunNPMRunDevstart, What's goingtohappenisthisfileserverdotJsisgoingtoberanandeverysingletimewemake a changeandclicksave, youseeit's gonnarefreshWe'regettinganair, obviously, becausethisisnotrealcode.
Soifwecomeinhereandwesayrouterdotgetandwhichisjustgonnabeat a slashandwewanttopassitinourrequesthoopsrequestand a responseAndfornow, we'lljustsayrezdotsendinparticles.
Sowehookedupourviewtoourrouteproperlyatarticlesslashnewnowinsideofourcontainer, wecouldjustcreate a simple H one, whichisgoingtobeourmainheader, andwe'regonnagiveitsomemarginonthebottomwillsaymarginbottomfourjusttospaceitoutfromtheformthatwillcomebelowit.
SothatmeansinourarticlesdotJshere, we'regonnahave a routerdotpostwhichisgoingtogotojustthisslashroutelikethis, andwe'regonnahave a requestand a response.
Sonowbackintoournewherewecanworkoncreatingalloverdifferentinputs, butinsteadofcreatingourinputsdirectlyhereinsideofthisform, I knowfor a factthatournewarticleinputsaswellasourarticleatitinputsaregonnabeexactlythesame.
SothisisgoingtorendertheexactHTMLinsideofforeignfieldsthat E.
J s andwecanjustsayincludewhichisgoingtoallowustoinclude a pageandwewanttotypeinthepathwhichinourcaseisformed, fieldsbecauseit's inthesamefolderandwe'llclosethisoffwithpercentgreaterthansymbol.
ButinordertostylethiswithBootstrap, whichwasat a classwhichisformcontrol, itsaveandrefreshAndnowit's styleperfectlythebootstrap.
Sowehavethisniceandputjustlikewedooverhere.
Oneotherthingthat I wanttodobecause I wanttomakesurethat I markthisinputasrequired, sothatwhenwetrytosubmittheform, it's goingtotellusthatthisfieldisrequired, whichisgoingtobeexactlywhatwewant.
Soalsowhat's comedownhereandwe'regonnacreate a submitbuttonsocials, create a buttonwhichhasthetypeofsubmit, andthisisgoingtohave a classwhichis E.
T.
N andBeattyandPrimary, whichwouldgiveusthisnicesubmitlookingbuttonandthenfortextquestionsputsafe.
Andwealsowanttospecifythetype, whichis, inourcase, goingtobe a string.
Sowe'regonnahave a requiredstringtitle.
Next, we'regonnahaveourdescriptionwhichinourcase, isgonnahave a typeofstringandit's notevengonnaberequired.
Wedon't alwaysneedtohave a description, andthenwe'realsogonnahavearemarkeddown.
Andinourcase, ourmarkdon't isgonnabe a typeofstringandwewanttomakesurethataremarkeddownisalsorequired.
Sowe'regonnasayrequiredoftrueNow, lastly, wewannahavethedatethatwecreatethisatsowe'regonnahave a createdatandthisisgoingtobe a typewhichisdate.
Andthenwecanalsospecify a default.
Andthisdefaultisjustgonnabedatedotnowanddefaulttakes a functionsowecanpassit.
A functionlikethis, whichisgonnacalldatethatnow.
OrwecouldjustcallitourdatedotNow, functionlikethiswithouttheparentheses, andit'llpassthisfunctionandcallthisfunctioneverysingletimewecreate a newrecord.
Soessentially, byspecifyingourdefaulteverytimewecreate a newarticle, ifthereisnocreatedat, it's justgoingtogiveittothecurrentdateasthecreativethattime, whichisexactlywhatwewantNow, inordertousethisarticleschemeOh, weneedtoexportthisbyusingmodulethatexports.
Thisessentially a sanethatwecanactuallyaccessallofthedifferentparametersfromourarticleforminsideofourarticlerouterightherebyjustaccessingrequestdotbodyandthendotwhateverwecallthissotitle, forexample, ordescriptionwherewecouldevendomarkdownwecanaccesseverythingfromourformonthatrequeststopbodyobject.
Andnowwe'vecreated a newarticlewith a title, a descriptionandmarkdownbasedontheexactspecificationsofourformoverhereandnow, wecansavethatarticlebycallingarticledotsaveandthisisanasynchronousfunction.
Sowejustwanttomakesurewesetthisupinsideofourown a sinkfunction.
Thisisgonnagiveusan I d forarticle, andthenwecouldjustsayrezdotredirectAndwedon't redirectourusertoearearticlesslashandthenwewanttoredirectthemtoourarticle i d fornow.
Now, inordertopreventtheuserfromactuallysubmitting a particlethatisnotvalid, we'regonnagointoourforeignfieldsandmakesurewespecifyaremarkeddownasrequiredNow, iftheytrytosavesomethingthathas a titleondescriptiononLeeforrefreshness, clicksave.
Whenwecreatethissection, it's gonnabepushedupreallyclosetoourarticletitle, which, ifwerefreshhere, youcanseejustlikethat, and I wanttojustadd a fewclasseshere.
We'rejustgonnaaddthattextmutedclass.
Sothatwaythisisgonnabegreattext.
Werefresh.
Youcouldseeitlookskindofgray.
Andalso, I'llsaymarginbottomoftwo.
Isthatwhatwehave a littlebitofspaceonthebottomforwhenweputourbutton?
Oneotherthingthat I wanttodoisactuallysortofthesearticlesbasedonwhentheywerecreatedat, and I wanttomakesurethattheolderarticlesareshowingupatthebottomandtheneweronesairfirst.
Sowe'regonnasortindescendingorder.
Andif I saverefresh, youshouldnowseethattheveryfirstarticlethatwecreatedisallthewaydownhere.
Soinsteadwe'regoingtousewhat's called a smug, whichisjust a versionofourtitle, whichisgoingtofitinthe U.
R l Sotomakeallofthesechangeswereactuallygonnamodifyourmodelsfolderhereandinsidehere, we'regonnaimportquite a fewnewlibraries.
Solet's juststopourserverrealquick.
Everyone a n p m i somenewlibraries, we'regonnado a librarycalledMarkedasbulls.
A librarycalledslug.
If I andthismarkedlibrary.
WhatthisdoesisitallowsustocreatemarkeddownandturnitintohtmlandslugIf I justallowsustoconvertsomethinglikeourtitleinto a Eurofriendlyslugwhichwecanuseinsteadofourtitle.
WealsowanttogetourslugIf I whichisjustgonnabehereequaltorequireofSluggofivejustlikethatandthe 1st 1 I wanttostartoffwith a slugif I becausethisisquite a biteasierthandoingaremarkeddownone.
Sonowwe'regonnacreate a newcolumnforourslug.
Thisisgoingtobe a typehereofstring.
Thisisgoingtohave a requiredoftrue, andwe'realsogoingtomakesurethatthisisunique.
Andwhatthisisgoingtodoisthiskindofforceareslugif I togetridofanycharactersthatdon't fitin a euro.
Soifwecreate a newarticlethat, forexample, had a coloninitinsteadthatisactuallygoingtoberemovedbythisslugif I hearwhenwehavestrictoftrueAndyounoticedthatwhen I triedtoaccessthenewroute, itgaveusanairwhichneedtostart.