I hope everyone is doing fine. We are going to start a new tutorial on Express.js. This one of the most important libraries. In the previous post, We had a small post on Express.js which was just running a server on the localhost. In this series of tutorials, we are going to celebrate the Express.js. We will cover one topic in each post. So without wasting time let's begin with the installation and running the server.
- First of all open the folder where you want to keep the project files and create a new folder if you don't have one.
- Open the folder and copy its adress.
- open Command Prompt and type
cd
copied address.
- Now type
npm init
and it will ask for some information if you want to skip with default then just press enter on every question.
- Now we need to install the Express.js file from Node package Module(NPM).
Type npm install express --save
- Wait for it and let the files installed.
Type
type nul > index.js
in Command Prompt to create a file with name index.js.Open the same folder in subline/vs Code/Atom. ( In my case I am using Subline)
Here you can see the file we just created. We will write our code in this file which is our main file
const express = require('express')
const app = express()
const port = 5000
app.get('/', (req, res) => res.send('Welcome to Hive Blockchain'))
app.listen(port, () => console.log(`For Hive example the app is listening at http://localhost:${port}`))
Copy-paste the above code in the index.js file.
- Now run the code by typing
node iindex.js
in the Command Prompt
- Now open this
http://localhost:5000
in the browser.
- If i want to add a second page I can just add this
- Stop the server and rerun it
- And I open this
http://localhost:5000/hive
I will see the message i entered in the code.
In the upcoming post I will explain how the thing works and what exactly our code is doing.
I think this much is enough for today. Now if you like the post please upvote and comment if you want to give me some advise
Congratulations @pakgamer! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :
You can view your badges on your board And compare to others on the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @hivebuzz:
Support the HiveBuzz project. Vote for our proposal!