Header Ads

What is Express And How to Use it on Node.Js

In this article, We will cover What is ExpressJS, How to Install Express in Nodejs and How to Create HTTP server using ExpressJs in Node Application with few lines of code. Before moving further make sure you should have already basic knowledge of JavaScript and Nodejs.

What is ExpressJS?


Express or ExpressJS is the most popular lightweight framework for building HTTP and HTTPS servers in Nodejs. Apart from this express is essentially used for pages Routing, handling GET, POST, DELETE request as well as for exporting modules.

How to Install ExpressJS.


There are many ways to install or import or download the express package in your nodejs application.

  • run npm command using Windows PowerShell.


npm i express --save


  • Now config your express server.


const express = require('express');
const app = express();

app.get('/', (req,res) => {
res.send('Hello World');
});

app.get('/login', (req,res) => {
res.send('LoginPage');
});

const PORT = process.env.PORT || 3000;

app.listen(PORT, () => console.log(`listening at port ${PORT}`));

Here you have successfully created your new express server.

  • Now start your server by hitting following command below and test it out.


node app.js

 

No comments