Hello Everyone
In this post, we will learn about how to create your own server and link your local HTML page with it. In this tutorial, We are going to use Express.js. So without wasting time let's begin the tutorial.
Open the VS code( Visual Studio Code) and open a black folder where you want to store your files.
Open the terminal. First, we need to install Express.js. Make sure you have already installed the node.js in your PC.
To install the express.js type
npm install express.js --savein the terminal.
- After successful installation, the response should something like this.
- create a new file
index.js
- Now copy-paste the code given below.
const express=require("express");
const app =express();
app.get("/",function(re,res){
res.send("welcome to the page. This is a post on Hive blockchain")
})
app.listen(8000,function(req,res){
console.log("server is running");
});
- After running the above script the server should be running on 8000 port and a message will be appear on the terminal which is
server is running
- Now open your browser and search
http://localhost:8000/
- As you can see our server is responding. We can also change the text size by adding
<h1>
- Stop the server and run again to apply the changes.
This much is enough for today. We will explore the express.js more in the upcoming posts. If you like the post please do upvote and comment