Express has some built-in the service layer, express handle the service requests using routing. The routing in Express maps HTTP verbs plus URI combo to an ask for the handler function. The routes are the application endpoint URI or path and HTTP request method (GET, POST, HEAD, PUT, DELETE ) and how the endpoint responds to a client request. In the example below, we displaying the different message with routing to specific URL in express.
When we make professional node apps, then we have to use standard routing. We will create the separate folder for the routes, views and static files as public in the app folder. All the route code kept in routes folder. Example index.js for the home page route and feedback .js for feedback page route.
Step1: Add the following code in app/app.js and we will have to add the corresponding view for the home page.
Add the following code in app/routes/index.js to route to a home page and we will have to create the corresponding view for the home page.
Add the following code in app/routes/teacher.js to route to URL localhost/teacher and /teacher/id and we will have to create the corresponding view for both teachers and teacher/id route. Express allows us to specify our routes as a string and to specify them as regular expressions.
Using Express with HTTPS
We can add the https to our Node apps. The express use built-in HTTPS module for HTTPS access and we have to supply certification key and the private key in Node to access our web HTTPS protocol. Simple example node apps with both HTTP and HTTPS
Example: Express apps with both HTTP and HTTPS