Below are the steps to set up a basic Express.js application
Step 1: Initialize a Node.js Project
Step 2: Install Express
Step 3: Create an Express App
Step 4: Run the Express App
//Step 1
mkdir my-express-app
cd my-express-app
npm init -y
//Step 2
npm install express
//Step 3
const express = require('express');
const app = express();
const PORT = 3000;
// Middleware to parse JSON requests
app.use(express.json());
// Define a route
app.get('/', (req, res) => {
res.send('Hello, Express!');
});
// Start the server
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
//Step 4
node app.js
© www.thecoderjob.com. All Rights Reserved. Designed by HTML Codex