Writing is not an easy task. Many seems to think that each post goes almost without thinking, when the reality is there a detailed plan involving the phrase, “what are you doing today for tomorrow’s post?“. And that’s it!, no more than 24 hours of planning for each post. The problem is that when you are dealing with many technologies at the same time, it becomes difficult to find references to explain some topics; and that is the reason for my today post: try explain a very fast way how to create a routing scheme with ExpressJs in NodeJs.
And as always I will share a step by step
1. Create a directory where the files from our NodeJs server will be stored. In my case is “E:\srcElBruno\Tests\NodeJs\Demo01\”
2. Open a Command Prompt and navigate to the previous location.
3 Install the Express package from NPM (Node Package Modules, all the information here). This is done with the command
NPM install express
4. Create a file named server.js in the root directory.
5 Add the following content within the same
6. Now, we launched our server NODE with the command
7. We have our app running! If you browse to the root of our server, on port 1337 (line 12), we will see the so classic as useless Hello World
If instead sail to the address http://localhost: 1337/elbruno will see a not so classic but not less vain “page of the bruno”
8. If we want to give you a bit of intelligence (not many) could change this redirection to make it directly against my blog
9. The complete reference of ExpressJs can be found here.
Saludos @ Home