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