Express is a web application framework for NodeJS, simplifying the process of building robust and scalable web applications. It offers a simple design, making it easy to create APIs and handle HTTP requests and also support the middleware. Express is a popular choice for creating web servers and APIs in JavaScript.
Steps to Create a basic Server Using ExpressJS:
Step 1: Install the express package in your application using the following the command.
npm install express
Step 2: Create a server in a file named server.js.
Javascript
// server.js const express = require( 'express' );
const app = express(); const PORT = 3000; // define the route app.get( '/' , (req, res) => {
res.send(`<h1 style= "color: green;" >Hello Gfg!</h1>`);
}); app.listen(PORT, () => { console.log(`Server is listening at http: //localhost:${PORT}`);
}); |
Start your server using the following command:
node server.js
Output: