00:01In the last lecture, we started setting up our server
00:03and now we need to take our HTML and not have HTML anymore
00:08'cause we wanna build it out on the server.
00:09To do that, we're gonna use a templating system
00:11that is called EJS.
00:13Through it, we're gonna inject our react data into that HTML
00:17that's inside of a template
00:19and enable us to create reusable template components,
00:22a lot more ably for static components,
00:25static information like our header information,
00:27maybe footer information, and so on and so forth.
00:30So by the end of this lecture, we'll have
00:32that integrated into our Express JS application.
00:36Alright, so the next step in our process.
00:38Right now we're working with basically static HTML,
00:42but in reality, what our goal is to move our react
00:46to run on the server.
00:47So to do that I'm gonna go into our folder
00:49and I'm just literally gonna go into our public folder
00:52and just delete our index.
00:54We don't need it anymore.
00:55So now that we don't have an index and we have the CSS files
00:58and the images, all that is still good.
01:00Oh, you know, let me undo that
01:01because I actually need this file.
01:03But I'm gonna go ahead and I'm gonna create a new directory
01:06here and I'm gonna call this file directory views.
01:11And I'm just gonna go ahead
01:12and grab our file, our HTML file for now.
01:16Just for the sake, just for this moment, I'm gonna take
01:19that file and just take it out of our public folder.
01:21We're gonna move it into views
01:23and we're gonna do some with thing,
01:24something with it in a minute.
01:26Now that we don't have the file inside of our public folder,
01:29we wanna basically render things out dynamically using
01:32a templating system.
01:34Now to be able to use a templating system, I'm gonna have
01:36to install another, something to append into our server.
01:40So to do that, I'm, again, I'm going to, I'm going
01:42to clear out, out my server break out of it,
01:44and I'm gonna go ahead
01:45and install a template engine, which is called EJS.
01:50Now there's a lot of different template engines,
01:52but we're just gonna work with that one
01:54and I'm gonna install it
01:55and we need it for our production environment.
01:57And I'm gonna install it.
01:58It's called EJS as it's installing.
02:01Let me continue and set it up.
02:03So, step number one, I'm gonna go into my application
02:05and at any point I'm gonna, I, I'm using the public folder.
02:09Great. So the first step, it's gonna check
02:11to see if something's there after I check
02:13to see if something is there,
02:15then we're gonna do the next operation.
02:17So in this case, I'm gonna set up our view engine.
02:21Basically I'm telling Express to use EJS
02:26to render things out.
02:27So now that I'm using EJS,
02:30whenever we call the render method,
02:31which we'll take a look at that in a, in a millisecond,
02:34the next step, I'm gonna go into our view itself
02:38and start creating it.
02:40So the view itself in generally speaking,
02:42you want to be organized.
02:43So I'm gonna go ahead
02:44and just create here in, in, in my view itself,
02:48I'm just gonna views, I'm gonna go ahead
02:50and create a new folder and I'm gonna call it layout.
02:53And I'm gonna go into my index file
02:55and I'm just gonna just push it right
02:57inside there. And I'm gonna go
02:58Ahead there and change our index
03:01to be something more generic.
03:03I'm gonna call it template or let's call it blank.
03:08Do ejs. And I'm gonna use e js.
03:12That's all good. And lemme just go ahead
03:14and close that index file.
03:15We're not going to use that file.
03:18And now that I have my, my file sitting there inside of
03:21that view, inside of that layout and layout,
03:23and it's called blank dot egs, let's go ahead
03:26and load that up into our application.
03:28And let's, let me show you the steps involved with that.
03:31So I'm gonna go into my server
03:33and in my server itself, what I wanna do is I wanna listen
03:36to a specific something.
03:39There's a lot of a lot of things
03:40that could happen on a server, but in my case, I want
03:43to go ahead and ask my route,
03:45and I'm literally gonna say it when a user reaches a certain
03:47destination in this case,
03:48when they reach the route destination,
03:50then I'm gonna go ahead
03:51and I'm gonna just get that respo, I'm gonna, I'm going
03:56to send that information.
03:57There's get and there's posts and there's other,
03:59but we're not gonna go deep into that world.
04:01But instead of that, I'm just gonna go ahead
04:03and create a get, which basically means there's no form
04:05that has been submitted in this case.
04:07Well, technically there could be a get form,
04:09but in our case we're really just loading up, uh, element.
04:12Now what's going on here is whenever a get happens,
04:15whenever the user gets a page
04:17or they're not posting something, they're getting a page.
04:19Then this callback will be called,
04:21this callback is gonna have the request information
04:24of the user and it's gonna have the response object
04:26that we're gonna be using to respond back to the user.
04:29And in our case, we really just want
04:31to do one very simple thing.
04:33We want to go ahead and we wanna respond with our
04:37render of what, of a specific layout.
04:41Now notice how I'm not gonna type your views.
04:43That is the default in Express
04:45and EJS, it's gonna look for it inside of the views folder.
04:49So I'm just gonna go ahead and set our layout
04:51and e well, in our case, I called it blank,
04:54but probably empty would be more appropriate.
04:58And in our case layout blank, it's gonna go ahead
05:00and call that blank, that EJS file.
05:03And I'm not gonna send a second parameter,
05:05but we will in the next lecture.
05:07And there we go. This will be our first rendering.
05:09And if I go ahead and say this, just running
05:11through this really quickly again, step number one,
05:14we installed EJS.
05:15Step number two, we went to express
05:17and told express use EJS as your template engine.
05:21Whenever we call the render next step, we went ahead
05:24and defined the path When the user goes to this route,
05:27in this case that means the route directory.
05:29And in that case, we don't want it on a post,
05:32we want it only when the user is getting the page,
05:34not when they're posting something or deleting something.
05:37In that case, when they're getting the page,
05:39we're gonna get, we're gonna use a arrow function,
05:41which it's first peram that will be sent to us
05:43as the either request information
05:45where we could gather information from the user.
05:48And the next is the response.
05:49And with the response we respond back to the user
05:52by using the dot render method,
05:54which then links back with our
05:56Our EJS templating engine.
05:59And we're literally telling it this is the file that we want
06:02to send back now if everything worked according to planned,
06:05if I go ahead and I run my server again and,
06:10and I run my server again,
06:12and once my server is running, if I go back here
06:14and I click here on refresh,
06:16we just still see the low world.
06:17But this time around it's coming from our templating engine.
06:21Now if you're wondering what's
06:22so great about using a template engine
06:24and not just static HTML, well that is part of our process
06:27because we want to inject inside of your information
06:30that is not static, which will start doing in
06:32the next lecture.
06:35In this lecture we integrated EJS into our express
06:38application and we're ready
06:40to move in the next lecture into actually integrating ES six
06:44and JSS support onto the server
06:46so we could start rendering React applications.