// Step 1: Import required modules
const express = require('express');
const bodyParser = require('body-parser');
// Step 2: Create an instance of the Express application
const app = express();
// Step 3: Use bodyParser middleware to parse incoming request bodies
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Step 4: Define a route for handling POST requests
app.post('/api/postData', (req, res) => {
// Step 5: Access data from the request body
const postData = req.body;
// Step 6: Process the data (example: log it to the console)
console.log('Received POST request with data:', postData);
// Step 7: Send a response to the client
res.status(200).send('Data received successfully');
});
// Step 8: Set up the server to listen on a specific port
const port = 3000;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});