Steps to Implement Routing in Express
Step 1: Initialising the Node App using the below command:
npm init -y
Step 2: Installing express in the app:
npm install express
Example: Below is the example of routing in express:
Javascript
// server.js const express = require( 'express' ); const app = express(); const PORT = 4000; // define route app.get( '/home' , (req, res) => { res.send( '<h1>welcome to w3wiki!</h1>' ); }); app.listen(PORT, () => { console.log( `Server is listening at http: //localhost:${PORT}` ); }); |
Start using the following command:
node server.js
Output: