const express = require('express'); const bodyParser = require('body-parser'); const app = express(); const PORT = 3000; // Use body-parser middleware to parse JSON and URL-encoded bodies app.use(bodyParser.json()); // For JSON payloads app.use(bodyParser.urlencoded({ extended: true })); // For URL-encoded payloads // Webhook endpoint app.post('/webhook', (req, res) => { console.log('Received Webhook Payload:'); console.log('Headers:', req.headers); console.log('Body:', req.body); // You might want to do something with the payload here, // e.g., save to database, trigger another service, etc. // Respond to the sender to acknowledge receipt // Many services expect a 200 OK response quickly. res.status(200).send('Webhook received successfully!'); }); // Basic health check endpoint app.get('/', (req, res) => { res.send('Webhook listener is running.'); }); app.listen(PORT, () => { console.log(`Webhook listener running on http://localhost:${PORT}`); console.log('Waiting for POST requests to /webhook'); }); // To run this code: // 1. Make sure you have Node.js installed. // 2. Create a new directory, e.g., `my-webhook-listener`. // 3. Navigate into the directory and run `npm init -y`. // 4. Install express and body-parser: `npm install express body-parser`. // 5. Save the above code as `app.js` (or `index.js`). // 6. Run it with `node app.js`. // 7. You can test it using a tool like Postman or `curl`: // `curl -X POST -H "Content-Type: application/json" -d '{"event":"test","data":{"id":123}}' http://localhost:3000/webhook`