Express JsNodejs

Node Js – Routing Simple and Easy with Express

Node Js - Routing Simple and Easy with Express

Views

Hello to all, welcome to therichpost.com. In this post, I will tell, Node Js – Routing Simple and Easy with Express.

Now a days, I am learning node js and What I do learn about node js, I share on my blog.

Nodejs is an open-source server environment which runs Javascript on the server and Express is a web application framework for nodejs.

Today I share about routing in node js with express js

Here is the pictures for routing pages:

 

nodejs_home_page

 

nodejs_about_page

 

Here are the working steps, you need to follow to add routing in node js:

 

1. Very First, you need to add express into your nodejs application:
$ npm install express --save
2. Second, you need to below code into your node js main file:
var express = require('Express'); // Import Express Package after Install it.
var app = express();

//localhost:3000/about
app.get('/about', function(req, res) {
  res.send('About Page');
});

//localhost:3000
app.get('/', function(req, res) {
  res.send('Home Page');
});
app.listen(3000); // Path Define localhost:3000

If you have an query related to this post, then please do comment below or ask question. 

This is my custom code and If you want to work with nodejs, then you have to install node js  first after it,  you can try my above code.

I want your thoughts on it because it is very important for me.

Thank you,

Happy Coding

Therichpost

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Positive SSL