express js

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 port ${port}`);
});
  1. Import the Express.js library by requiring the 'express' module.
  2. Create an instance of the Express application and assign it to the variable app.
  3. Set the port variable to 3000.
  4. Define a route for handling GET requests to the root URL ('/') using app.get().
  5. Inside the route handler function, send a response of 'Hello World!' back to the client using res.send().
  6. Start the server to listen on the specified port (3000) using app.listen().
  7. When the server starts running, a message will be logged to the console indicating that the server is running on the specified port.