,

Creating a Server with ExpressJs in MERN Stack: A Guide to Web Development

Posted by

Making of Server in ExpressJs | MERN Stack || #webdevelopment

Making of Server in ExpressJs | MERN Stack || #webdevelopment

ExpressJs is a popular web application framework for Node.js that simplifies the process of building server-side applications. In this article, we will discuss how to create a server using ExpressJs in the MERN (MongoDB, ExpressJs, React, Node.js) stack.

Step 1: Install ExpressJs

First, you need to install ExpressJs using npm. Open your terminal and run the following command:

npm install express

Step 2: Create a Server

Next, create a new file – let’s call it server.js – and add the following code:


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

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

app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});

Step 3: Run the Server

To run the server, navigate to the directory where the server.js file is located and run the following command:

node server.js

Now, open your browser and go to http://localhost:3000. You should see ‘Hello World!’ displayed on the page.

Congratulations! You have successfully created a server using ExpressJs in the MERN stack. Now you can start building your web application using MongoDB, ExpressJs, React, and Node.js.