Node Js Crash Course

Node Js Crash Course


Published at - Aug 13, 2021

In this crash course, we will explore Node.js fundamentals including modules such as path, URL, fs, events and we will create an HTTP server from scratch without Express and deploy it to Heroku.

Crash Course Info

Date – Feb 7, 2019

Channel – Traversy Media

Transcript –

this video is sponsored by dev Mountainif you’re interested in learning webdevelopment iOS or UX design devMountain is a 12-week design anddevelopment boot camp intended to getyou a full-time position in the industryto learn more visit dev mountain comm orclick the link in the description belowhey guys welcome to my no js’ crashcourse so in this video we’re gonna betalking about what note is and we’lljump in and take a look at some of thefundamental modules some of thefunctionality that nodejs includes we’regonna build a web server with just noteitself it’s important to know that we’renot going to be using Express or anyother framework or anything like thatthis course will be followed with anexpress crash course but far too manytutorials on node include Express andit’s important to know that they’rethere they’re different note is aruntime expresses a framework that’soften used with node so I want to touchon some of the core node modules at theend I’ll even show you how to deploy noto Heroku which is an app hostingplatform so we’ll look at some slidesand then we’ll jump in and we’ll startexploring nodejsalright so first off what is node it’s aJavaScript runtime as I mentioned it’snot a language it’s not a framework or alibrary or anything like that thelanguage is JavaScriptonly instead of JavaScript running in abrowser environment as it has runtraditionally it’s actually running onyour machine as a service or a runtimeit does this by using the v8 JavaScriptengine which is the same engine that theGoogle Chrome browser uses it’s verypowerful it’s very fast node and v8 isthey’re mostly written in C++ which isan extremely powerful and fast low-levellanguage so essentially what all thismeans is we can use JavaScript as aserver-side language just like we couldPython PHP C shop or any otherprogramming language so what should youknow before learning node I woulddefinitely recommend that you learn atleast the the basics of JavaScriptobjects arrays conditionals all thatgood stuff I would also suggest learningsome of the newer feeteachers es6 plus like arrow functionspromises etc now since you’re dealingwith server-side you’re gonna be dealingwith HTTP quite a bit as you’ll begetting requests from the client to yourserver and then sending back a responseand of course frameworks like Expressmake this much easier but neverthelessyou should sue should still understandfor instance some of the important HTTPcodes like what is a status 200 a 404 or500 etc maybe even learn about HTTPheaders things like that so note is alsoused a lot for REST API in microservices which 99% of the time they’regonna be serving Jason as the contenttype or the data type so I would suggestlearning Jason which is actually verysimple you could probably learn it in acouple days if you don’t already know itand that’s that’s pretty much it maybethe MVC pattern the Model Viewcontroller pattern which is used prettycommonly with node but again it’s it’sjust a plus you know it’s not somethingyou have to know before you startlearning node alright so why use nodewhy is it a good choice for server-sidetechnology over let’s say PHP or Pythonso node is extremely fast efficient andit’s also highly scalable and one of thereasons for that is it’s event-drivenand it runs on a single loop and it’snon-blocking okay so it has anon-blocking i/o model and if thatsounds like gibberish i’m gonna go overthe over what that means a little bitmore in the next couple slides so noteis also very popular in the industryespecially in startups there’s a lot offull stack jobs out there looking forpeople that no node I’m sure many of youhave heard of the mean stack or the myrnstack note is often used with front-endframeworks like react view and angularbecause it allows you to use the samelanguage on both sides so rather thanhaving a JavaScript front-end and thenlike a c-sharp or Python back-end youhave the same language on both the frontend and back end which can be anadvantage all right so as I mentionednodejs is non-blocking and it’sasynchronous okay it works on a singlethread and it usedis non-blocking i/o or input-outputcalls so something like PHP is usuallysynchronous and it runs on multiplethreads so every time a request is madeit spawns a new thread and these threadsthey take up system memory and caneventually max out okay can max outwhatever the the memory load handles sosince these languages are synchronousand asked to essentially sit and waitfor one process to complete beforestarting the next now nodejs on theother hand works in an asynchronous wayand it’s non-blocking on a single threadand this thick single thread canliterally support tens of thousandsconnect of connections which are held inwhat’s called an event loop and thisoptimizes throughput and scalability inapplications with many i/o operationswhere you don’t want to use node is withCPU intensive apps so long runningcalculations things like that all rightso here is a diagram of the event loopand how it works so it runs on a singlethread and events are run asynchronouslybasically when an event is triggered acallback fires so this way the systemdoesn’t have to run a process sit andwait for it to end and then run the nextlike it does in many other synchronouslanguages it simply fires an event or aprocess and moves onand once that event is fulfilled it runsin the loop and you don’t have tounderstand this completely to be to beable to start to work with node andwrite node.js applications I just wantedto kind of summarize a little bit howthis works in because it’s the reasonthat note is so fast and efficient allright so let’s talk a little bit aboutwhat types of projects node is good forso I mean the short answer is anythingthat’s not CPU intensive right so IOoperations are asynchronous and usuallythat is for instance making a request toa server sending data to a servergetting a response things like thatthose are i/o operations however runningyou know CPU calculations that that canblock the whole server and can make carethat application very slow so it’s notreally goodfor those types of things so like restAP is and micro-services note is greatfor a lot of times you’ll be building aback-end API with node where you won’teven be serving for instance HTML pagesyou’ll be serving Jason you’ll do allyour database interaction and stuff likethat within nodejsand obviously it works with any databaseyou can use relational databases howeverit’s very popular MongoDB is verypopular to use with node because it’svery fast it’s also very scalable sonode and actually make a reallygood team real time services so thingslike chat applications note is great forcrud apps so blogs shopping cards socialnetworks basically any application whereyou’re just fetching stuff from thedatabase displaying it you’re updatingthe database things like that note isgreat for as well also tools andutilities as long as they’re not CPUintensive so these are all things thatnote is fantastic for all right so whenyou download and install node JSU youget something called NPM which is thenode package manager and it’s used toinstall third-party packages or modulessuch as frameworks libraries and smallertools and when you install a package itgets stored in a folder called nodeunderscore modules which will R will becreated automatically when you installsomething and then any package ordependency you install will get listedin a file called package jason whichevery node project should include itholds info about your app like the namethe version and it also lists all thedependencies which are packages thatyour app needs to be able to run ok youcan also create NPM scripts to runcertain tasks such as web servers andwe’re going to be looking into all ofthis stuff a little laterI do have an entire crash course on NPMwhere I go deep into all the commandsand stuff like that if you’re interestedsome common commands we have NPM initwhich generates the package JSON fileand then if we want to install somethingwe simply do NPM install and thenwhatever it iswe want to install in this case it’sExpress which is a very popular webframework now this will install itlocally in your application in yourapplication folder however you can alsoinstall things globally on your systemby just adding the – G flag ok sothat’ll put it on your system so thatyou can run the commands or whatever itincludes you can run and run thatanywhere in your system alright somodules are a huge part of node node hasa large set of core modules that itcomes with we’re going to be looking ata bunch of the common onesyou also have modules or packages thatyou install with NPM and then you canalso create your own modules which aresimply files that have an export ok thisway you can include variables functionsclasses or anything else from one fileyou can include that in another andwe’re gonna do this we’re gonna look atthe syntax basically you create avariable you set it to require whatevermodule you want in this case it’s thepath module which is a node core moduleand then if you want to create your ownfile and bring it in you can simply addit to a create a variable require andthen set the path of the file so in thiscase dot slash just means that thisthere’s a my file yes file in the samefolder ok so I think that’s enough forthe talk and the slides let’s go aheadand jump in and let’s start working withnode.js alright so the very first thingthat you need to do obviously is installnodejs so you need to go to node.js organd either download the long-termsupport version or the current which isthe latest version with the latestfeatures i usually download the currentbut it doesn’t matter whichever one youwant to use should be fine so i’m justgoing to open up a terminal real quickor if you’re on Windows you can open upyour command line your command promptand I just want to show you before wejump into a text editor when you startcreating files I want to show you thatnode comes with something called arepple which is a read eval print loopand it basically allows us to runJavaScript directly in the console so ifwe just type in first of all just makesure you have installed with no – -version and you can see you’ll also haveNPM as well all right but if we go aheadand we just say node and that’s it wehit enterit’ll bring us into the rebel and fromhere we can actually type in JavaScriptso for instance we can say 1 plus 1 andit’ll give us 2 we can create variablesso I’ll say Kant’s name equals a stringof Brad and it’ll give me back undefinedjust because that that statement doesn’treturn anything but if I go ahead andtype in name you’ll see it gives me BradI can also do a console dot log name andyou’ll see it will just log Brad allright we can also create functions so ifI say like function hello and let’s justhave it actually we’ll just say return[Music]hello and then we’ll just concatenate onname so we’ll create that function andnow if I say hello I can run thatfunction alright so I just wanted toshow you that we can in fact runJavaScript from the console if we haveno installed however this is not thisisn’t something that at least I usepretty much ever but it is possible solet’s just control C or command C justto get out of that alright so I’m goingto close up the terminal and head intovs code and for now on I’m going to beusing my integrated terminal down hereand I have a folder open which is emptyit’s called node crash course and thisis where I’ll be creating all my filesso the first thing that you’re going towant to do usually when you’re creatinganything with node is create apackage.json file and you don’t have tocreate it manually you can simply runnpm in it and it’s gonna by default justask us some questions like the packagename so I’ll keep the folder name as thedefault the version hit enter that’sgood description let’s say ode crashcourse entry point is basically yourmain file by default it’s index J s butI’ve also seen app J s server J s thoseare some other common file names testcommand we don’t need that gitrepository author you put your name andthen license default is ISC that’s fineand then we’ll hit enterand it will create a package.json withall that stuff in it all right now thethe the biggest purpose of package Jwell I shouldn’t say the biggest purposebut one of the main purposes is to storeall your dependencies if yourapplication uses something you installfrom NPM then it needs to be listed herebecause if you move to another computeranother server whatever it may be whereyou want to run your app you’re gonnarun npm install and that’s gonna installall the packages that are listedall right so later on i’m gonna be usinga very small module called UUIDjust to generate random IDs so i’llinstall that now just to show you if ido npm install UUID so as you can seeover here it created a node modulesfolder and it was put inside of thereand if I reload my package Jason you cansee it gets added as a dependency okaynow you can also have dev dependencieswhich are dependencies that you justneed for development so we’re gonna beusing something called node Mon whichwill make it so that we don’t have tokeep restarting our server and I want toinstall that as a dev dependency so Icould say npm install and i could eitherdo – – save – dev and then the name ofthe module which is node 1 but what ilike to do is just – upper case D whichis a shorter way of doing it so if we goahead and run that it should get addedas a dev dependency all right so nowright here you can see dev dependenciesand we have node Mon so when you’reready to deploy or move this appsomewhere else you don’t include themnode modules you can delete that andthen just run npm install actually i’llshow you that real quick if I were todelete this whole and this has a lot ofstuff in it now because it has all thedependencies of these modules and thenany dependencies that those have so thisthis folder gets huge so you never wantto deploy this to a host if I deletethis and I have these listed in mypackage Jason I can simplynpm install and it’s going to thenrecreate the node modules folder withall that stuff in it okay so hopefullythat makes sense and we’ll use thosemodules later I just wanted to show youthat so let’s create our main file whichis index dot JSP a Jason this justtracks all of our dependencies with theversions and by the way everything thatwe install comes from the NPM j/s orgrepository or website that’s whereeverything is stored there in thatregistryall right so in index J s I’m just gonnasimply do a console dot log and let’sjust say hello from nodejs and save nowI can run this file by simply sayingnode index dot j s and it prints it outin the terminal in the console and whenwe run a file we don’t actually have toput dot J s so just node index that’lldo the same thing all right so we canrun any JavaScript we want from theterminal or any JavaScript file now mostof the time you’re going to havemultiple files and these these otherfiles are basically modules you’re gonnacreate whether it’s a class or afunction or an object or something thatyou’re going to export to bring in toanother file so I want to touch on thatso let’s create a new file we’ll justcall this person dot J s and inside herelet’s go ahead and create create anobject called person and we’ll set thisobject to have a name of John Doe andlet’s say age 30 now if I want to usethis this person object somewhere else Ican simply say module dot exports equalsperson ok and if I save that and I goback to index j s and I want to bringthat in I can simply create a variablecall it person and set it towire and then since it’s a file and notan actual module that we installed or acore node module we want to put the pathwhich is dot slash meaning the currentfolder and then person and then I’ll goahead and console dot log person allright and then we’re gonna run nodeindex and you’ll see that it’ll give usthat object obviously if I wanted justthe name I could do person dot name andwe get John Doe okay now a lot of timesyou’ll have a class you could even youcould have a function that you couldexplore it but let’s say we wanted aclass in this file called person andwe’ll create a constructor and this isjust a JavaScript class and he has sixclass I’m not gonna go over JavaScriptsyntax it’s not what this video is aboutit’s about nodes specifically so I’m notgonna explain every little bit ofJavaScript but let’s say this takes in aname and an age and we set this dot nameto name and this dot age to the agethat’s passed in and we’ll create amethod called greeting and let’s goahead and just let’s do a console logwe’ll put some backticks in here andwe’ll say my name is put our variablesyntax and we can save this dot name andI am this start age okay and then we’llgo down here and let’s make sure wechange this to an uppercase P we’reexporting the whole class and we’ll savethat and let’s bring in person uppercaseP and now we can instantiate a personfrom it a person object so we’ll sayperson 1 equals new person pass in JohnDoe and 30 and let’s go ahead and runperson 1 dot greeting so now if I runthis node index file you’ll see my nameis John Doe and I am 30 okay so weexported the person class and we broughtit in and we call we instantiated aperson and then called thereading method now it might seem likethis file here is just getting rundirectly like this but actually when youinclude a module like this it it’swrapped in what’s called a modulewrapper function and I’m just gonnapaste this in just to show you we don’twant to run this code this is actuallywrapped around all of thisso we have access to module requireexports also the file name and Dern aimokay double underscore file name andDern aim we’re using module dot exportsdown here we can also use required tobring things in and we also have accessto these two and just to prove that toyou I’ll go ahead and say console dotlog let’s do well do dur name and filename okay I’m just going to comment thatout cuz that’ll give us an error and ifwe run node index you’ll see before weget the output of the greeting we getthis which is the dur name okay it’sjust the full directory of this file andthen the file name includes the fulldirectory as well as the name of thefile which is person G is okay not indexbecause we didn’t run this in index weran it in person J s okay so just wantedto show you that those are availablebecause we’ll be using this dur name andfile name later on and that’s where itcomes from alright so let’s go ahead andclose that up I think that’s that’spretty much it as far as exporting andin requiring now you might be wonderingwhy we’re not doing like import personfrom person like we would in like let’ssay react or anything es6 and that’sbecause node hasn’t implemented this yetif you want to be able to use the syntaxfor now you have to actually you have toimplement babel to to compile it tocompile to es6 this is the last featurereally of es6 that isn’t perfected innode yet and I’m hoping that that thiscut that this is available soon that wecan do thisbut just to show you if we try this andwe run note index it’s gonna give us anerror unexpected identifier okay so yeahwe can’t do that just yet but hopefullysoon so and by the way this is calledcommon J s this this method of use thismethod of module is common J s the otherway that I just showed you is es6 okayso now let’s take a look at some ofnodes core modules now if we go back tothe nodejs website we go to docs andwe’re using version 11 this will give usall the core modules as you can see onthe left here as well as documentationon some other stuff but let’s take alook at the path module which is usedquite often it’s basically used to workwith file directories files in directorypaths as you can see and thedocumentation for these modules isreally good because it has all thedifferent methods that are available sofor instance basename shows you theparameters that it takes shows you whatit returns it shows you an example sothis is very helpful and I’m just goingto go over some of these okay I’m notgoing to go over every single method ofall of these these modules but just somestuff that you might run into so let’sjump back into vs code and these arebasically gonna be for reference so I’mgonna create a new folder calledreference because I want you guys to beable to have this if you want to go backand look at some of these methods so I’mgonna create a file in here called pathunderscore demo dot j/s and we’re gonnawant to run this file so I’m gonna CDinto reference and then to run this wecan say node path demo which obviouslyright now isn’t going to do anythingbecause there’s nothing in itso let’s bring in the path module so wecan say require path and it’s it’s acore module so we don’t have to includelike a file path or anything we don’thave to npm install path because it’salready included with nodeso let’s take a look at some of themethods so first one is base nameactually I’ll put what it does so itgets the base file name and remember ifwe do a console log of double underscorefile name what that gives us is theentire path and the file name at the endso what Basin what path dot base namedoes is it’ll just give us the file nameso if we wrap this in path dot base nameand we go ahead and run this you’ll seewe just get path demo Jas so they’ll beyou know if you’re working with filesthey’ll you’ll probably have cases whereyou’re gonna have to dissect parts of itand this will get you the base name nowif you want just the the directory namewe can do that as well so we can sayconsole.log path dot dur name and thenlet’s pass in the file name whichincludes the the path and the filenameand that will give us just the directorywhich in this case dur name doubleunderscore dur name will give us thesame thing but this way we’re using thepath module to get this okay so we canalso get the extension and we’llactually be using will actually be usingquite a bit of this stuff later when wecreate our HTTP server but let’s sayfile extension so if we do path dot txtand you’ll see with envious code as soonas I put a dot it shows us all theavailable methods so we’ll do X name andlet’s pass in our file name and now ifwe run this you can see that it gives usa dot J s okay so it’s just going togive you whatever the extension is youcan also create an object with differentparts of the path so let’s say createpath object and we do this with theparse method so let’s do console.logpath dot parse and pass in our filenameand see what that gives us and it givesus this object with the root directorybase extension and name which is thefile name without the extension and wecan access any part since this is anobject we can access any property likelet’s say we want the base we could saydot vase and it just gives us just thatbase right here just that value alrightand then the last thing I want to showyou is join so this will can’t talkwhile I spell concatenate so concatenatepaths and we use join for this so let’ssay we want to create like the currentdirectory slash test slash hello dotHTML let’s say we wanted that so wecould say path dot join and it’s justgoing to put together each parameter wepass in so we’ll take the the der namewhich gives us the current directory andlet’s say we want to then do test ok soa folder called test and then a filecalled hello dot HTML ok so let’s getrid of this and let’s see what this doeswhat this gives usso we’ll clear this up and run the fileand you’ll see we get the directory nameso that’s the first part and then slashtest which is this part and then helloHTML now this works really well when youhave issues with with delimiter x’basically with windows you have you havedifferent delimiters sometimes you’llhave this for the back slash and then onMac and Linux you’ll have the forwardslash and this will put the correctdelimiter in which usually resolvesitself book itself but I have writtensome system cases where it doesn’t soit’s good to use this path join andwe’ll be using this later on now thereare a lot of other methods that you canuse with the path module here but I’mnot going to go over all of them I don’twant to waste too much time here so thenext thing I want to look at is the filesystem module or the fs module so inreference I’m going to create a fullfile called FS underscore demo dot J Sand we’re gonna bring in here FS sorequire FS and we’re also going to bringin path again because we’re going to beusing that as well alright and firstthing I’m going to show you is how tocreate a folder okay so this will createa folder on our system and we’re gonnasay FS dot make dur now by default theseare asynchronous and let me just showyou what I mean so if we go to C filesystem and this shows us all thedifferent methods and if we go to makedur you’ll see that there is make durwhich is the one we’re using which isasynchronous which means that it takesin a callback okay so anything you wantto do after you put in your callbackhowever there is a synchronous versionof most of these methods so as you cansee there’s make tear sync which doesnot take in a callback so basically ifyou use a synchronous version you’llwait until the process is complete untilit moves on with the asynchronous youcan call it and then and then just youknow keep going and it’ll finish in thecallback so it’s asynchronous so in mostcases you’re going to want to use theasynchronous version however I wanted toshow you there is a synchronous versionso like I said this takes in the folderyou want to create so I’m actually gonnacreate a folder called test inside ourcurrent directory so I’m gonna take thepath module and use join and let’s jointhe current directory name and thenlet’sadd a folder called test ok so that’swhat we want to create the secondparameter of make dar is options and wedon’t have any so I’m just going to putan empty object and then a callback sowe can say like function and this willtake in a possible error and we cancheck for that error and if there is onethen we can throw that error in theconsole and then we’ll just do a consoledot log and we’ll say folder created allright now you can do it this way withfunction but I like to use arrowfunctions so I’m going to get rid ofthat the function text and then just putan arrow and since I only have oneparameter of error I don’t actually needto use parentheses here so I’m gonnasave this and let’s go ahead and runnode FS underscore demo so we get foldercreated and if we look in our referencefolder we now have a folder called testok so that will create a folder now wecan also create files and there’sthere’s a method called open that youcan use to create a file however if youwant to write to it right away you canuse write file and that will create itand write to it so let’s go ahead andsay create and write to file so let’sactually copy this because all of theseare pretty similar they’re allasynchronous so instead of makedirectory or make derp we’re gonna usewrite file and for the path let’s dosame thing current directory test andlet’s do we’ll create a file calledhello dot txt ok so it just takes in apath to a file that you want to createnot txt txt and then the secondparameter is gonna be the content thatyou want to write so let’s just sayhello worldand then this will give us back andpossible error we’ll check for it ifnothing goes wrong then we’ll just sayfile written – all right so save that Ido have the prettier extension in vscode so it just formatted it a littlebit so let’s go ahead and run thiswhoopsdo hear file already exists oh because Iwe’re trying to create a folder herethat already exists so I’m gonna commentthat out however it did run this and itdid create the hello dot txt and if welook inside actually I guess you knowlet’s try to run that againall right so let’s look in hello textand now we get hello world all right nowlet’s say we wanted to add to it likehello world and then we’ll say I lovenodejs now if I were to copy this andput this down here and change this tospace I love nodejslet’s see what happens so we’re gonnarun both of these right files okay youcan see it was file written 2 is heretwice but if we look inside it just saysI love nodejs because what right filedoes is it over writes whatever isalready in there if you want to appendto it then you want to use a pend fileso let’s change this to a pend file andthen since I want to run both of thesetogether and this is asynchronous we’regonna take this whole thing and put thisinside the callbackok so we’ll put that right here andlet’s say file pend and save and nowwhat I’ll do is just delete the hellotext all together so it recreates itokay so right file should recreate it itshould add hello world and then in thecallback we’re running a pend file whichshould add I love nodejs so let’s try itlet’s make sure that’s saved we’ll runit creates the file and if we take alook it says hello world space I lovenodejs alright so that’s right file on apen file now if we want to read file wecan do that as well let’s just commentthis stuff oh and let’s say read fileand I’m just gonna copy just copy thisokay so read file and the file we wantto read is gonna be the hello text soI’m just gonna add in here hello dot txtand let’s see for the sec secondparameter of read file you’re going towant to put the character encoding whichis going to be utf-8 if you don’t putthis and you want to get the data that’sin the file it’s just going to give youa raw buffer it’s not going to give youthe actual data since we put theencoding we can actually put after thepossible error the data that’s in thefile and let’s go ahead and console.logthat data and of course you could dowhatever you want with the data so let’ssee that should work let’s save this andrun the file and we get hello world ilove nodejs so it’s reading what it whatis in this text file okay and then if wewant to rename a file we can do that aswell so let’s change this to renamecomment that out so rename the secondparameter is gonna be the fot the pathand the new file name so I’m gonna copythis whole path dot join and put that asa second parameter and let’s change thename of the file to it’ll just say helloworld I guess okay and it’ll give us apossible error and then it’s justconsole log file renamed up Sweeneyquotesall right so let’s save that run it filerenamed and now you’ll see we have helloworld dot txt all right so those arejust some of the things you can do withfiles with the FS module again there’sthere’s many more methods if you want tolook at the documentation and feel freeto have the repository in thedescription if you want to add moreexamples and then make a pull requestfeel free to do that just for it to helpother people so let’s see in referencelet’s now look at let’s look at the OSmodule which is pretty simple so it’s anew file OS underscore demo dot j/s andwhat this does is it gives usinformation about our environment aboutour operating system so let’s do constOS equals require OS so let’s say wewant to get the platform meaning WindowsMac whatever so let’s do console.log OSdot and it has a method called platformso it’s save this and let’s run node ohs demo and you can see Darwin so Darwinis the the platform for Mac ok meaningI’m on a Mac if you’re on Windows youget win32 on Linux you get what do youget on Linux I forget I forget but it’sit’s something differentso that will get us the platform we canalso get the CPU architecture so if wedo a console log OS dot Arc actuallyit’s a method so we need parentheseswe’ll run that x64 the chances areyou’ll get the same thing next we canget CPU core info so we can get thatwith OS dot CPUsif I run that it’ll actually give us anobject with information for every coreof the CPU and you can see I have quitea few here this is an iMac Pro which hasa bunch of cores I forget it was like 12cores or something like thatit’s an Intel Xeon and it just shows youall the different analytics all right sothat’s CPU core info we can also getstuff with them information about thememory so like the free memory soconsole and this is really cool becauseyou can you can build apps that thathave to do with with your system youknow so let’s do free mem oops I’m sorryOh s dot free mem and if we run thatyou’ll see right here it gives us theamount of free memory and we can alsoget the total memory with total mem runthat so is the free memory is the totalmemory of my system yours will bedifferent we can also get for instancethe home directory so we can say OSstarts homeand run that you’ll see that my homedirectory is user slash Brad Travis IIand then last thing I’m going to showyou is the uptime which is the amount oftime your system has been up so it’s twoOS start up time and it gives you thenumber of seconds that your system hasbeen up so I mean you can be creativeand create some cool applications withthis stuff so I’m going to close that upand the next thing I want to look at isthe URL module so in reference I’m goingto create a file called URL underscoredemo dot Jas so obviously this thisworks with URLs so let’s do const URLequals require URL now used to use URLdot parse which is now deprecated ibelieve now you want to just instantiatea new URL object so I’m going to sayconstant my URL equals new URL and thenlet’s pass in here it’s a HTTP mywebsite.comlet’s do slash hello dot HTML let’s putsome parameters in here whoops spelt alittle wrong so let’s put someparameters in here like ID equals 100and status equals active because a lotof times you’re going to work with URLsthat have parameters like this so firstthing I want to show you how to do isget the serialized URL so basically getthe straight-up URL and we can use theobject we created dot href ok so we canuse the a that property so we’ll runnode URL underscore demo we’re runningthe file and it just gives us the entirething you can also use the two stringmethod which will give you the samethingso if we do to string like that you’llsee we get the same thing all right nowlet’s say you want to just get the hostor the root domain which in our casewould be my website comm so we could domy URL dots host run that and you’ll seewe get my website comm now you can alsoget the host name by doing my URL dothost name and if I run that notice ofthe same thing the difference betweenthis is that host name doesn’t includethe port so if we have like port 8000like that and we run it notice that hostname doesn’t get the port host does okayso that’s the difference there in factwe’ll just say does not get poor allright so next let’s look at the pathname so it’s console.log my URL dot pathname take a look at that it shows slashhello dot HTML so it just gives us theactual path the actual file let’s seenext we’re going to look at theserialized query so basically thestraight-up query parameters so we’ll doconsole log search if we take a look atthat search whoops my URL dot search andit gives us thisso basically everything after thequestion mark okay now if we want toactually create an object from this wecan use search params so let’s sayparamsobjectsfor that we just do my URL dot searchparams okay so if you run that now youcan see we get an actual object with theID value and the status and the valuenow we can actually add parametersdynamically as well so if we want to addper am we could say my URL dot searchparamsappend and let’s append let’s say ABCand then the value one two three okay soif we do that and then again we log thesearch params let’s see what that givesus okay so you can see that now we’veadded on an extra set of parameters soABC and one two three we can also loopthrough these if we wanted to so this isthe last thing I’ll show you guys so toloop through the params we could take myURL dot search params we could do a foreach and whoops alright so this takes ina function I’ll use an arrow I’ll sayvalue and name and let’s just do aconsole.log and let’s put in some backticks and we’ll put the name colon andthen the value all right so let’s runthat and you can see it’s gonna loopthrough and it’s gonna give us eachparameter each key value pairall right so that’s the the URLparameter I’m sorry the URL module sonext thing I want to look at is eventsokay so using the event emitter so if wego to the documentation and we go toevents let’s see so much of the nodecore API is built around idiomaticasynchronous event-driven architecturein which certain kinds of objects calledemittersnamed events that cause function objectsor listeners to be called so essentiallywe can create an event emitter okay anevent emitter class and then we can emitevents and have listeners that listenfor those events and then do somethingwhen they’re fired off so it’s it’s kindof hard to explain so let me give yousome examples I’m gonna go ahead andcreate in reference a new file calledevent underscore demo dot Jas alright sofirst thing we’re gonna do is bring inthe event emitter and we’re gonna setthat to require events alright and thenwe want to create any middle class solet’s say class my emitter extends eventemitter which we just brought in allright I’m not gonna put anything in herebut I’m gonna go ahead and init class orin it I should say an it object so I cansay consulates call this my he met heractually want to do yeah lower case notthe same as the class lower case so myemitter and we’ll set that to a new myemitter object alright and then what wecan do is create an event listenerso we’ll say my he MIT our dot on so wewant to say on event then let’s put acallbackhe’s an arrow function and we’ll justconsole.log event fired all right nowany time ie MIT this whatever I put inhere event this is gonna run so if I godown here let’s say an it event and Isay myhe met our dot omit event and we runnode event demo we get event fired andif I can just run this a bunch of timesand every time I run it it’s gonna runwhatever is right here alright so what Iwant to do is is give you a bit of amore practical example using eventemitter by creating a logger alright solet’s go ahead and close this up andthen in the root not in the referencebut in the root I’m gonna create loggerdot J s and let’s let’s do the samething by bringing in event emitter setthat to require events and I’m alsogonna bring in that UUID module rememberI installed that back in the beginningI’m gonna say require UUID and all UUIDdoes is create some random Univ was itUniversal I forget what it’s called itstands for it’s a certain format of ofan ID and just to show you what it givesus let’s do console.log UUIDand there’s different versions so whatwe want to do is dot version four andthat will generate just a random ID andi can show that to you if we CD dot dotback into the root and I run node loggeryou’ll see that this is what thatgenerated for us and we can generate asmany as we want so if I run that you cansee it just generates different ones nowI want to create a class here calledlogger and I want to extendevent emitter okay and then we’ll have amethod in here called log that takes ina message okay and then when this iscalled we want to call a vent a raise anevent so we’re gonna take I’m gonna saythis this pertains to the class rightand we’re extending event emitter whichincludes the omit okay and our referencefile here we called my emitter I’m sorrywe called yeah my emitter dot emithowever this method is gonna call thisdot he meant since we’re extending eventemitter and let’s emits an event calledmessage and let’s add in here an IDwhich will set to UUIDdot version four and then let’s also addthe MSG that we pass in okay and this isthe same as doing this like that soevery time we call log it should show anew ID with the message that sent nowI’m gonna export this module dot exportslogger and then in the index J ass let’sclear all this out and let’s bring inlogger from require whoops am i doingI’m mixing es6 in common j s so Constaequals require dot slash logger cuzremember it’s a file and then let’s goahead and create or instantiate a loggerbecause remember logger is a class so weneed to instantiate it and then let’scall log r dot onmessage okaynow this is gonna give us a call backwith some data so for this data let’sjust console.log and let’s let’s saywe’ll say calledlistener and let’s put in the dater aswell I shall change this to back ticksand then we’ll put data okay and then weactually have to call the log method sounder here let’s just say log r dot logand let’s send a message we’ll just sayhello worldso now let’s call the index file alrightso this is wrong I don’t know why I didthis because this is an object this dataobject should be the ID in the messageso let’s actually let’s put quotesaround call listener and then just put acomma here and then we’ll show the datalike that okay so now let’s run thisagain and we get called listener and itshows ID which is a generated ID fromfrom the UUID module and then themessage that we passed in and we cancall this as many times as we want withdifferent messages hi hello and we’ll goahead and run that and you’ll see thateach time it’s the listener is gonna getcalled and it’s gonna show a new ID witha new message and this may not be themost practical example but you can justsee how this works you can even omit anevent it’s gonna call whatever whateverwe put in here and you could use yourimagination and maybe even bring in theFS module the file system module and logthe ID and the message to a file okay sothat you can just use a pen file and youcould have a file that has all your logsalright and maybe you can use that havethat use that as your homeworkassignment for this course alright so Iwant to move on because we’re reallyrunning out of time here and I want toget to the HTTP module so we’re gonnacreate a whole server here a very basicserver but nevertheless it is stillgonna be a web server but before we dothat I just want to end the referencefolder create a file called HTTPunderscore demo dot jsut can see thatthe bear of the bare minimum just to geta server running and then we’ll createthe the main server in our index file solet’s clear this up and let’s CD backinto reference and let’s go ahead andbring in HTTP so we want to require HTTPall right now we want to create a serverobject and we do that by taking HTTP andcalling create server ok now this takesin a function however I’m going to usean arrow function so I’m gonna put ourparameters that we need which is requestand response put an arrow function andwhen we get a request we want to thenwrite a responseso we’ll do res dot write okay as amethod call right which basically justoutputs to the browser and let’s sayhello world and then we want to end sores dot end all right now in order forthis to run it needs to take in it needsto listen on a port so we’re going totack on to this dot listen and then thistakes in a port number I’m gonna put in5,000 and then I’m just gonna put a callback here to console log and we’ll justsay server running just so just so itshows something in the console so serverrunning alright so we’ll save that andthen let’s run node HTTP underscore demoand you can see server running and it’sin we can’t type anymore so now let’s goto ourbrowser and let’s go to localhost portso colon 5,000 and we get hello worldokay so that’s that’s the the the mostsimple web server you’re ever going tosee in your lifenow I want to create something usefulwhere we can actually load HTML pages wecan load you know CSS files things likethatso we’re gonna create an actual webserver and we’re gonna just close thisfile and to stop the server from runningyou just want to do a ctrl C okay andlet’s CD dot dot to get back into theroot alright so we’re done with thereference folder so let’s open up indexJ s now it’s important to know thatactually you know what let me just takethis and put this in the log or J s soyou guys have this as a reference soinstead of exporting it I’m just runningit in here ok so it’s important to knowthat if you use a framework like Expressit makes this stuff a lot easier withExpress you can specifically you can saylike you know I want my app to receive aget request to the page slash abouts andthen you can have a callback functionyou can do what you want so it makes itmuch easier however I think it’s it’s agood thing to understand how to do thiswithout express at least just load basicweb pages of different content types andso on so we’re gonna be using all allcore node modules so let’s bring in HTTPand let’s also bring in path and let’sbring in FS okay so now we’re kind ofputting everything together that we’velearned so we want to create a newserver object however I’m gonna put itin a variable called server so HTTP dotcreate server and then this is going totake in a function with request responsenow remember we have to listen on theportshowever instead of tacking it on we cannow take that server object or variableand we can say dot listen all right nowwe want to put a port in here howeverI’m gonna put the port inside of avariable alright now I could just setthis to like five thousand however whenwe deploy this it’s not always gonna runon five thousand it’s gonna run onwhatever you know whatever our our hostis going to decide which is going to bein what’s called an environment variableso it’s going to be in process dot e NVdot port okay but we want to do or fivethousand so basically it’s gonna firstlook for this it’s gonna look for theenvironment variable and then if that’snot found then it’s gonna run it on fivethousand okay now in here we just wantto put port okay and then let’s put acall back with a console log and we’llput in some back ticks and we’ll sayserver running on port and then we’lljust put in the port number okayso inside here let’s um I showed you howwe could just you know we can writewrite something out to the browser butthat’s not what we want to do we want toload a file so I’m going to testlet’s test to see what the URL is nowrequest object we have actually you knowwhat we’ll do is let’s just console.logthe request URL okay just so we can seewhat that is now if I run my server if Isay node index you can see serverrunning on five thousand if I go to fourfive thousand and reload it’s gonna hangbecause we didn’t send any responsehowever if we look and look if we lookin the console you can see slash okay sothat’s the request URL now if I were togo to let’s say slash about and go backyou’ll see that we get slash about so wecan see what URL is getting is gettingcalled so let’s do an if statement hereand we’re gonna make this more efficientafter I’m just doing this for an exampleso let’s say if requests dot u RL isequal to slash then we know that’sthat’s the index page and instead ofjust writing out something like I coulddo you know Raz dot and you don’t evenhave to do dot right and then end youcould simply do res dot and and put yourcontent in here and you can even putHTML in here like let’s say home alrightso if I save that and let’s do control cand restart the server and then go tolocalhost 5,000 we get home alright I’mactually going to make this smaller sothat we can see both at the same timenow if I were to change this to let’ssay homepage and save and reload noticeit doesn’t change because I have to godown here and manually restart theserver now it says home page this iswhere a node Mon comes in and veryuseful and remember we installed thatback in the beginning as a devdependency so this node mon here wecould use let’s go down here and wecould say nomaaan and then index so instead of nodenode Mon I’m sorry we can’t do thatbecause we didn’t install it globally sowhat we want to do is create an NPMscript okay if we did install nodemont√≥n globally we would we be able todo that however that’s not the bestpractice it’s not what what I wouldsuggest what we can do is go to scriptsokay and we don’t need this test scriptso we can replace this and I’m gonnajust do start all right now for start Ijust wanted to run the standard nodeindex just like we were before howeverthat’s not going to update unless wekeep restarting the server but thereason I’m putting it here is becauseonce we deploy it’s gonna call thisstart and that’s what we want we don’twant to use node Mon in deployment soI’m going to add another script of devand I’m gonna set that to node Mon indexso instead of just running with withnode it’s gonna use node Mon whichconstantly watches it so we don’t haveto update so let’s save this clear thisup and let’s say npm run dev okay sowe’re using NPM to run this script righthere which will run node Mon okay andnow you can see that it’s running onfive thousand now if I go back to indexand they change this back to home andsave node Mon is continuously watchingit so if I reload it changes I don’thave to manually control C and restartit okay so node Mon is an excellent toolso back to our code here instead ofdoing this I mean this if I do a youknow control U or whatever what is itcontrol option you and look at oursource code we have no doctype we havenothing we don’t even have a contenttype if I were to open my dev tools andgo to network and take a look at solet’s make this bigger for a second andtake a look at thecontent-type which I don’t even think itwill say yeah it doesn’t even say but wewant this type to be HTML so we can adda content type by saying R as dots righthead so basically right to the headersand we want this to be a 200 responsewhich means everything is okay and thenpass along the content type and we wantto set the content type to text slashHTML all right so let’s save that andnow when we reload you can see that weget status 200 and if we take a lookdown here we have content type text HTMLokay so that you definitely want to havethat in there now I don’t want to justjust output the HTML here I want to loada file so I’m going to create a foldercalled public and basically this iswhere I want all of the public HTMLfiles CSS anything like that so I’mgoing to create an index dot HTML andlet’s also create in about dot HTML okayso an index I’m just going to generatesome boilerplate and just put home pageput an h1 we’ll say welcome to the homepage and then we’ll copy this we’ll goto about change the title to about andwe’ll just change this to about allright so we have two HTML pages in thepublic folder which right now thatthey’re not getting loaded in any waythey’re just there so what I want to dois if the request URL is slash I want toload the home page so I could use the FSmodule I’m just going to go right abovethis for now so use the FS module dotread fileand let’s do let’s look at actuallylet’s use path dot joined and will dodouble underscored our name and thenpublic and then we want to load theindex.html okay and then secondparameter will be our callback andinside here is where we want to put thisstuff however remember when we read afile we get first possible error andthen we also get the data which I’mactually going to call content okay andthen we’ll paste that in okay now whenwe end we don’t want to oh we don’t wantto output this this h1 we want to outputthe content of the file okay and we alsowant to make sure it’s a status 200 andits type HTML so I think I haveeverything here we should probably checkfor the error as well but let’s savethat and reload and we get welcome tothe home page okay so to reiterate we’rechecking the URL if it’s slash which itis we’re gonna read the file index.htmlthat’s in the public folder and we’regonna then check for an error we’regonna set the status and the contenttype and then we’re gonna simply servethe the HTML page okay so hopefully thatmakes sense and then of course we couldcheck for the request URL being slashboats and we could load the about pageso if we reload we go slash about therewe goactually I’d probably well that’s goodnow let’s say we wanted to we wantedthis to be like like a REST API so wewouldn’t be serving HTML we’d be servingJason so let’s actually add in let’schange this let’s change this to ifslash API slash users let’s let’s getrid of this stuff so normally what wewould do is fetch data from a databaseand serve that however I’m gonna justgonna hard code in it say users equalsan array so name I’ll say Bob Smith age40 and we’ll do one more John Doealright so we have this users array andthen we would want this to be a 200response however this is Jason contentso we wouldn’t do text HTML we would doapplications slash Jason alright andthen we’d need to turn this objectJavaScript array of objects into Jasonso we’ll do res dot end and we would dojason dot stringify users okay so let’ssave that and now if I were to go tolocalhost 5,000 slash API slashusers there we go we get our jason okayso if you were to build some kind ofMicra service some kind of rest api youcould do this but you probably useExpress or something like that I’m justshowing you how to do it with just nodeokay so this really isn’t very efficientlike we’re gonna stick to we’re gonnastick to just serving HTML files and soon however this isn’t efficient becauseevery single page we want to add wewould have to do you know if this orwhatever and also we need to be able tohandle for instance CSS okay if we wantto include a CSS file or images oranything like that so this isn’t thisisn’t gonna workso let’s comment this out because Istill want you guysyou have this but let’s start over sowe’re gonna go under all that stuff wejust did now I want to make the filepath dynamic so let me show you what Imean I’m gonna say build file path andwe’re going to create a variable herecalled file path and set it to path dotjoin the current directory name and thenpublic and then let’s say basically Iwill I want to set this to the requestURL so for instance if if we go to slashabout HTML then I wanted to load aboutdot HTML if we go to slash contact HTMLI want it to look for contact HTMLhowever the route is a little differentbecause it’s just slash so I’m going touse a ternary operator here I’m going tosay for request dot URL if that is equalto slash then I want to load index dotHTML in the public folder elseokay colon is else that I want requestdot URL whatever that is all right solet’s actually do let’s just do res dotand just so we can see what this path isgonna be so let’s do a console log offile path alright and we’re gonna justgo to the root and you’ll see the PIit’s going to show anything that senseso even the favicon but you can see theindex.html because this is the root if Igo to slash about HTML it shows youpublic slash about HTML so so this filepath is correct in terms of what we wantto load now we’re also going to want toset the content typeokay like HTML as a content type of textslash HTML CSS is text slash CSS Jasonis application slash Jason and so on sowhat I’m gonna do next just get rid ofthat for now is I want to get theextension of the file and you guysremember how to do that right we dolet’s create extension aim as a variableand set it to our path module ext namemethod and pass in our file path sothat’ll give us the the extension of thefile that’s that’s being loaded okay arebeing sent now we’ll set a content typelet’s set the initial content typeso let’s content type is gonna be bydefault text slash HTML because that’swhat we mostly expect however we want tocheck the extension and then set thecontent type and we’ll use a switchstatement for that okay so let’s sayswitch and we want to check theextension name all right now I’m justgoing to paste these in because it’sjust going to take too long for me totype out so we’re basically gonna checkeach case so if it’s j/s we want textjavascript if it’s CSS we want text CSSjason if it’s an image that should havethat content type or i’m sorry a PNG itshould have that if it’s a jpg it shouldhave that okay so that’s basically allthe file types that i want a handle forthis server alright so that takes careof setting the file path and setting thecontent type now we need to actuallyload a file so let’s go down here let’ssay read file so we’re gonna do FS dotread fileand we want to pass in the file pathwhatever that is and then it’s going togive us our possible error and thenlet’s say content alright now we didn’treally go over errors the error codeshowever we want to check for a specifictype of error and this error will beit’ll be an object that’ll have aproperty called code so I want to say inhere if the error dot code is equal to eand o ENT okay II know net and o net andwhat this means is the page isn’t foundokay and in most cases that’s what it’sgoing to mean so let’s say page notfound so the way that I want to handlethis you could handle it however youwant but I want to load an error page soin my public folder I’m going to createa file called 404 dot HTML and I’m justgoing to copy one of these HTML pagesand simply say and the title not foundwill say 404 not fun obviously you wouldhave this be much more stylish it wouldbe an actual website but I’m just tryingto show you how to create the server soif the page isn’t found let’s do FS dotread file again and you can see thereason that I went over all thosemodules there you guys wouldn’t knowwhat this was if I didn’t go over thethe boring stuff earlier so read file wewant to pass in path join so we want thedirectory name public and then we wantto load that 404 page so 404 dot HTMLokay and then the second parameter willbe the callback with the error and thecontent it’s actually close this up sowe have the error and the content andthen herewe want to first of all send a 200response so I’m gonna just copy thatline so right head 200 and it’s gonna betext slash HTML and then we want to sendthe content so let’s say res dot end andlet’s say content and let’s specify thatwe want it to be utf-8 all right so ifit’s not if it’s not found it shouldload that now let’s go to the end ofthis if right here and let’s put in elseso basically if it’s a different errorso still in within the error but if it’snot this code then it’s gonna be someserver error so most likely a 500alright so for that I’ll just we’ll do ares dot right head and we’ll send astatus of 500 and then let’s just do ares dot and and I’m just gonna put inhere server error and then the code soerror dot code not really an elegant wayto handle it but whatever it’s fine sonow if there’s no error so at the end ofthis if right here let’s say else ifthere’s no error then that’s a successsuccessful response so again we’ll writea 200 response and it’s going to be anHTML file and then we just want to loadthe content ok and the content is gonnabe this alright so hopefully that makessense I’ll reiterate real quick so let’sstart at the top which is straight youknow actually the top is up here who arecreating a server that gets a request inresponse ok every time a file is sentthen we’re gonna we’re basically goingto look in the public folder and we’regoing to valuewhatever this is request dot URL if it’sslash we’re gonna load the index if notwe’re gonna load whatever that file iscalled about HTML contact whatever okaythen we’re gonna get the extension andwe’re gonna evaluate the extension andset the content type based on that okaythe initial being HTML and then we’regonna read the file if there’s an errorwe’re gonna check for this error codewhich means that it’s not found thenwe’ll load the 404 some other error thenwe’re just gonna send a 500 if it’ssuccessful send a 200 response and we’regonna send the HTML file and we’re gonnaoh I’m sorry we did this wrong it shouldnot always be HTML it should be whateverthe content type is good thing I didthat okay I think that yeah that shouldbe right and then we’re gonna finallyjust send the content of the file okayso let’s go ahead and save this and Ithink we should it should work hopefullylet’s go back let’s reload about okayand let’s go to the home page and thatwas about dot HTML and then we getwelcome to the home page now we shouldbe able to also include CSS files so inpublic if I say new folder CSS and newfiles style dot CSS and let’s just dobody will say background dark colorwhite and let’s reload oh we get includeit so back in index.html let’s say linkto dot slash CSS slash style dot CSS andwe want this on all pages so let’s savethis go to about paste that in save itgo to 404 paste that and save it reloadand you can see the CSS is working so ifI go to about dot HTML that works now ifI go to something that doesand exist like whatever we get our 404page okay so it’s working nicely and ifwe if I open up the network tab andreload you’ll see that the document iswe get a 200 response it’s a text HTMLand if we want to look at the CSS it’s a2-under response and the content type istext CSS so you want to make sure you’regiving the right status codes you’regiving the right content types becausenow you’re working server-side okay ifyou’ve been working as a front-enddeveloper with you know react or viewand so on you probably have been just onthe side that is making the request butnow you’re actually serving the responseok so learning about HTTP is essentialall right so I think that’s pretty muchit obviously this isn’t really like aproject or anything like a website orapplication but I wanted to just getinto the specifics of node and some ofthe core modules and so on so the lastthing I’d like to do is just a simpledeployment to Heroku and the main thingto remember as far as the code thatwe’ve written is the port you want touse this process in the port ok you alsowant to make sure that you have yourstart script as node and then index orwhatever your main file name is okaybecause Heroku is going to look at thosethings now in order to push to Herokuyou need to sign up for an account let’sgo to Heroku comm and you just want tosign up I already have an account so I’mjust going to log in and you know if youjust create an account you won’t seeanything here but all your apps willshow up as these weird names here unlessyou rename them but you’re gonna needthe CLI tools so if you search forHeroku CLI just Heroku CLI and click thefirst link download and install and ifyou’re on Mac you can download theInstaller or use homebrew Windows usethe Installerubuntu and then other installationmethods as well but you want to get thatinstalled okay once you have it let’s goahead and stop our server with ctrl Cokay once you have it you should be ableto say Heroku – – version I believe Ihave it installed yep so if you haven’tinstalled it’ll show and then you’regonna want to log in through theterminal so let’s say Heroku login soI’m gonna use my email and passwordwhich I believe that’s it okay so nowI’m logged in now the way that we theway that we pushed Oroku is with git soyou need get installed if you don’t havegit installed just go to get – SCM commgo ahead and download and install itmake sure you have it okay and then wewant to initialize the git repositorynow I don’t want to push my node modulesfolder in fact I don’t want to push myreference or anything like that eitherso I’m gonna create a new file herecalled dot git ignore and this is not ahold on get ignore this is not a gettutorial so I’m not going to you know goover everything about git I do have acrash course if you’re interestedhowever we can put node modules in hereto prevent it from getting pushed alsoreference I don’t want that gettingpushed or log or J s or person dot JSPdon’t need those we just want the themain site the main server we created okso now let’s do get an it to initializethe repository let’s do get add alllet’s make a commit so get commit – Mand say initial commit ok so once wehave that done we can then say let’sclear this up we can say Herokucreate okay so with our account it’sgoing to create a new new app and it’sgoing to give us some weird domain nameand if I go back to my dashboard andreload you’ll see that limitless meadowthat’s what it created so next thing wewant to do is click on that and go todeploy and just grab the command to addthis as our remote repository so thisright here we want to copy that and thenpaste that in our terminal okay so nowthat’s added as a repository we alreadydid the add and the commit now all wehave to do is push to Heroku master tothe master branch so let’s say git pushHeroku master okay and this is going topush our application to Heroku sets anyenvironment variables that it needsokay so build succeeded all right so nowyou can go to the URL or you can just doHeroku open and that will open it inyour browser and there it is so as youcan see this is now deployed to theInternet our nodejs app so if I go toslash about HTML there’s our boat pageif I go to something that doesn’t exist404 not found all right guys so I knowthis was a long video if you stayed tillthe end I I genuinely really appreciatethat I really do if you if you can spendan hour and a half watching a video ofmine I really appreciate thatso thank you and hopefully you gotsomething from this even if you’ve usednote in the past hopefully picked up acouple things at least but thanks forwatching again I appreciate it and I’llsee you next time





About author

Harendra
Harendra Kanojiya

Hello, I am Harendra Kumar Kanojiya - Owner of this website and a Fullstack web developer. I have expertise in full-stack web development using Angular, PHP, Node JS, Python, Laravel, Codeigniter and, Other web technologies. I also love to write blogs on the latest web technology to keep me and others updated. Thank you for reading the articles.



Follow Us

Follow us on facebook Click Here

Facebook QR
Scan from mobile
Join our telegram channel Click Here
Telegram QR
Scan from mobile