This Sort Of Routing Is What Is Used In Most Modern Day Web Applications
If the command is executed successfully, the following Output will be shown when you run your code in the browser.
Output:
From the output,
- You can clearly see that we if browse to the URL of localhost on port 3000, you will see the string Welcome to Guru99 Tutorials displayed on the page.
- Because in our code, we have mentioned that our default URL would display this message.
From the output,
- You can see that if the URL has been changed to /Node, the respective Node route would be chosen and the string "Tutorial On Node is displayed.
From the output,
- You can see that if the URL has been changed to /Angular, the respective Node route would be chosen and the string "Tutorial On Angular" is displayed.
Sample Web server using express.js
From our above example, we have seen how we can decide on what output to show based on routing. This sort of routing is what is used in most modern day web applications. The other part of a web server is about using templates in Node js.
When creating quick on-the-fly Node applications, an easy and fast way is to use templates for the application. There are many frameworks available in the market for making templates. In our case, we will take the example of the jade framework for templating.