In this section, we'll explain how to set up a basic HTTP server using Node.js and Express. This server setup is a fundamental part of any web application, allowing it to listen for and respond to incoming requests.

Process

On the index.js file of root directory

  1. Importing Required Modules:
  2. Creating the Server:
  3. Port Number:
  4. Listening for Connections:

Detailed Steps

  1. Starting the Server:

  2. Handling Errors:

  3. Stopping the Server:


Code Overview

Here is the code snippet that sets up the server connection:

const http = require('http');
const app = require('./src/config/express.config');

const server = http.createServer(app);

server.listen(5500, '127.0.0.1', (err) => {
    if (!err) {
        console.log("Server is running on port 5500");
        console.log("press ctrl+c to discontinue server.....");
    }
});

Conclusion