Node JS – Part 4

Hi Friends,

Now, in today’s discussion, we’ll delve further and look into the View Engine. Now, in this case i am going to discuss Razor like view engine known as Vash. Now, in order to install the 1st, this time i go ahead and use npm with command prompt as shown below in the screen shot. Now, once that is done it will get updated in the package.json as well.

Now, in the code side, i just need to include the view engine. This time i don’t need to call via require rather in a different way and then i’ll use render keyword to render the view as shown in the below screen shot.

Now, the next thing here is i need to create the views folder as all the views supposed to be in views folder. Now, one point to note here, this is kind of convention which needs to follow. Now, in that folder i’ll create one text file and name it index.vash as shown in the screen shot and then i’ll put some razor like HTML inside

Now, we can go ahead also create Layout page like we have in MVC. So, for that i again go ahead and create one text file with the name layout.vash and put the common sections as shown below in the screen shot. so, as you can see below in the layout page i have used ‘@html.block’ to inject the index page in there and back in the index i have javascript call back function to implement the same. Here, I have used the keyword ‘extend’ to wire up the file which index is looking for and in this case it is ‘layout’ and then the callback function passing in the model which is being passed to the page. Then, we need to define the block with that particular which we are interested to fill in and then usual HTML tags.

With this i would like wrap this session here, in the next segment, we’ll see more on controllers and service. Till then stay tuned and Happy coding.


2 thoughts on “Node JS – Part 4

    • This is node js implementation. Basically node js is a server side framework written in javascript for building websites. so, it means you are creating your client side and server side implementation both in javascript and this is the step by step demo for the same.

Comments are closed.