ItSolutionStuff.com

How to Create Route in Node JS Express JS?

By Hardik Savani • June 1, 2021
Node JS

Hi Dev,

In this tute, we will discuss how to create route in node js express js. you'll learn node js express routes example. you will learn node js simple route example. We will look at example of express js routing example. Here, Creating a basic example of node js routing example express.

In this example, i will give you very simple example of get and post method route and show you output as well. so let's see step by step simple routing with node express example.

Create Node Project:

you can run bellow command to create node app.

mkdir my-request-app

cd my-request-app

npm init

Install Express:

npm install express

Create Server.js File

let's create server.js file with get and post route.

server.js

var express = require('express');

var app = express();

app.get('/', function(req, res){

res.send("This is a simple example of routing with ItSolutionStuff.com!");

});

app.post('/hello', function(req, res){

res.send("You just called the post method with ItSolutionStuff.com!");

});

app.listen(3000, () => console.log(`App listening on port 3000`))

Output:

Get Method

Post Method

i hope it can help you...

Tags: Node JS
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Node JS Read and Write Json File Example

Read Now →

Node JS Find and Update Object in Array Example

Read Now →

How to Get Data from Json File in Node JS?

Read Now →

How to Remove Element from Array in Node JS?

Read Now →

How to Push Element in Array in Node JS?

Read Now →

How to use Underscore JS in Node JS App?

Read Now →

Node JS Sort Array of Objects by Value Example

Read Now →

Node JS Foreach Loop Array Example

Read Now →

How to Create and Use .env File in Node JS?

Read Now →

Node JS Http Request with Headers Example

Read Now →

Node JS Express Form Submission Example

Read Now →