How to create a basic server using Express?
Last Updated :
31 Jan, 2024
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
const express = require( 'express' );
const app = express();
const PORT = 3000;
app.get( '/' , (req, res) => {
res.send(`<h1 style= "color: green;" >Hello Gfg!</h1>`);
});
app.listen(PORT, () => {
console.log(`Server is listening at http:
});
|
Start your server using the following command:
node server.js
Output:
Output
Share your thoughts in the comments
Please Login to comment...