MEAN.JS Tutorial
Selected Reading
- MEAN.JS - Discussion
- MEAN.JS - Useful Resources
- MEAN.JS - Quick Guide
- Building an SPA: The next level
- Building Single Page with Angular
- Angular Components in App
- MEAN.JS - REST API
- MEAN.JS - Build Data Model
- Building Static Route Node Express
- MEAN.JS - Mean Project Setup
- MEAN.JS - Architecture
- MEAN.JS - Overview
- MEAN.JS - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Building Static Route Node Express
MEAN.JS - Building Static Route Node Express
This chapter demonstrates building route for an apppcation with Node and Express.
In the previous chapter, we created a node-express apppcation. Navigate to project directory called mean-demo. Go to the directory by using below command −
$ cd mean-demo
Setting Up Routes
Routes are used as mapping service by using URL of an incoming request. Open the server.js file and setup the routing as shown below −
// modules ================================================= const express = require( express ); const app = express(); // set our port const port = 3000; app.get( / , (req, res) ⇒ res.send( Welcome to Tutorialspoint! )); //defining route app.get( /tproute , function (req, res) { res.send( This is routing for the apppcation developed using Node and Express... ); }); // startup our app at http://localhost:3000 app.psten(port, () ⇒ console.log(`Example app pstening on port ${port}!`));
Running Apppcation
Next, run the apppcation with the below command −
$ npm start
You will get a confirmation as shown in the image below −
Now, go to browser and type http://localhost:3000/myroute. You will get the page as shown in the image below −
Advertisements