Building an e-Commerce website with Node – Part 06 – Creating a home route in Node

A route is an URL. The home route is the home URL. The home URL of this website is dan.saigon.ro. The home URL of the MyESop website would be localhost:3000 since the server is installed on my computer and 3000 is the port we have set up. So, when you open your browser and go to the http://localhost:3000 you will get something. Let’s do it!

In the server.js file (right bellow var app = express();) we are going to create the route to the home page of the website.


app.get('/', function(req, res) {
  res.json("This is awsome!");
}); 

get() means “Hey, server, give me …”
‘/’ means the home page
req means you are requesting something to the server
res means the server responses with something (a web page for example). In our case the server responses with json data.

In order to check if the code works properly, first you have to start the server by typing the command nodemon server then open your browser and go to http://localhost:3000.

home route in Node.js

As you can see everything works properly. Of course we are going to modify this route and create more routes for all of our pages.

Leave a Reply