Learning Express.js-- installation and Hello World Example
Hello Everyone
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
cdcopied address.
- Now type
npm initand 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.jsin 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.jsin the Command Prompt
- Now open this
http://localhost:5000in 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/hiveI 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
Leave Learning Express.js-- installation and Hello World Example to:
Read more #programming posts
Best Posts From ProGrammer
We have not curated any of pakgamer's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From ProGrammer
- What do you think your Password is Secure?
- Nodejs Tutorial-- Sending Email using NodeMailer
- Node.js Tutorial --Reading and Writing files
- How to install Nodemon-- Express.js Tutorials
- How to use Range Element in a simple voting tool
- Learning Express.js-- installation and Hello World Example
- How to Compile your C/C++ code on the Visual Studio Code.
- How to check Voting Power And Resource Credit of Hive Account Through dhive
- How To Send Message TO WhatsApp Using JavaScript/Node.js-- Twilio
- How to add Custom prefix to your Discord Bot. Discordjs Tutorial
- HiveJs Tutorials --Learning how to transfer HIVE/HBD thorugh HiveJs
- Fetching API -- JavaScript Tutorial
- Learning Local Storage in JavaScript..
- Hivejs Tutorials-- #3
- Learn jQuery. Learning Events/Methods
- Learn jQuery --- Learning Selectors
- Learning JQuery-- Understanding the basics
- TypeScript for beginners -- A quick start
- How to Stream Hive Blockchain Transactions.-- HIVED
- Grand Theft Auto V (GTA 5) is now free on Epic Games Store.