Setting up a basic Express.js application is a relatively simple process. To begin, create a new directory for your project and navigate to it in your terminal.

Next, install the Express.js package with the following command:

npm install express –save

Once the package is installed, create an app.js file in the same directory. This is where you will define the Express application.

In the app.js file, add the following code:

const express = require(‘express’);
const app = express();

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

const port = process.env.PORT || 3000;

app.listen(port, () => {
console.log(`App listening on port ${port}`);
});

This code will create an Express application that listens for requests on port 3000 and responds with “Hello World!” when a request is made to the root URL.

Finally, run the application with the following command:

node app.js

You should see the following output in your terminal:

App listening on port 3000

Now you can access the application in your browser by visiting http://localhost:3000. You should see “Hello World!” displayed in the browser.

Leave a Reply

Your email address will not be published. Required fields are marked *