English 中文(简体)
Building Static Route Node Express
  • 时间:2024-11-03

MEAN.JS - Building Static Route Node Express


Previous Page Next Page  

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 −

Running Apppcation

Now, go to browser and type http://localhost:3000/myroute. You will get the page as shown in the image below −

Node Express Advertisements