Hi, Nodejs developers, we hope that you have gone through our last blog about Node.js and their kinds of purposes.
Today we will share something essential about routing in node js. Node is a cross-platform technology. Routing is core heart of any web programming language. In older days we were performing routing by lazy techniques by passing parameters using “?“ and simple post. But now as technology has grown up, routing becomes smarter.
In node, we can perform routing by many ways. But today we are going to lead on express only. You can also achieve routing by URL or other packages.
Now, give us a chance to give you a brief introduction about how node is getting worked by creating a simple host (a node server and request to the node for HTTP) as this is the basic part of doing routing.
For this, we require having npm installed on our machine.
What is Require?
Achieve Routing Using Express
1) Setup Server using Node
2) Install Express Package
3) Create Routing and use Express
1. Setup Server
2. Install Express Package
a. $ npm install express
3. Use of Express in Routing
I have set simple “Hello”
This was an example of GET, you can also use POST, DELETE, PUT
First, we have to create a server where we have set port and make a listener for HTTP on that port. Now in the browser when you hit http://localhost:8081 we will require a package express and create app instance, that app instance will handle our application request and our code will work like micro framework like slim and lumen.
At 9series, We are working with node.js for routing in node using modules like url, express and path. We are providing solution with front-end and back-end solution using laravel, node, vue and angular, etc.
Dahl was impelled to build Node.js after reviewing a file upload progress bar at Flickr. The most interesting thing was browser did not know how many files have been uploaded and for that the browser needs to question the Web server.
Dahl scrutinized limited possibilities of the most well-known web server in 2009, Apache HTTP Server to deal with lot of concurrent connections (up to 10,000 and more) and the widely recognized way of creating code (sequential programming) is that code either blocked the entire process or proposed multiple execution stacks in the case of simultaneous connections.
Use Of Node.js
Basic uses of Node Js are:
Node is using NPM(Node Package Manager) for package download. NPM is most recommended package manager for open source. Another package manager you can use is bower, etc.
After analyzing many statistical reports, we have found that Node.js is the fastest growing and most significant development language in the current scenario. With 3.5 million users and annual growth rate of 100%, Node.js is getting fascinated everywhere.
Below survey reveals the type of development work Node.js users do, the other technology they use with Node.js, which languages they plan to use more, and which they plan to use less in the coming months, and more. Following graph shows the usage of a node by different package managers for downloading node-packages.
And we have found another survey where nodejs was being used in the following fields of development.
Why Node js is so popular ?
1. CSS Busting
2. Elixir Notification For Web and Desktop
3. PHPUnit Testing Using Node
4. SASS and LESS Pipelining
5. Caching Purpose
6. Task Pipelining
7. Single Threading Request Mechanism