Configure your server

Learn to set up a server to manage incoming webhooks.

Now that our webhook is ready to deliver messages, we'll set up a basic Express server to handle incoming payloads.

Writing the server

We want our server to listen to POST requests, at /webhook, because that's where we told EverTransit our webhook URL was. Because we're using ngrok to expose our local environment, we don't need to set up a real server somewhere online, and can happily test out our code locally.

Let's go inside the project created in the Setup your server section and set up a little Express app to do something with the information. Open the index.js file and copy and paste for our initial setup which might look like this:

index.js
const express = require('express');
const PORT = 3000;

const app = express();

app.use(express.json());

app.post('/webhook', (req, res) => {
    const body = req.body;
    console.log(body);
    return res.sendStatus(200);
});

app.listen(PORT, () => {
    console.log(`Listening at port ${PORT}`);
});

Start this server up executing node index.js from your terminal.

Since we set up our webhook to listen for ride.created events, go ahead with your dispatch and create a new ride for testing purposes; you can cancel it later. Once you've created it, switch back to your terminal. You should see something like this in your output:

Success! You've successfully configured your server to listen for webhooks. Your server can now process this information in any way it sees fit.

Last updated