Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
I want to build my own webhook dispatch server using node js?

I am trying to build a webhook server using node js. If any user sets their server URL as a hook using API provided by me, then my webhook server should respond to that user server.

I got this idea from the Facebook Messenger Chatbot application which uses the same approach.

Server 1 - My Server

const express = require("express");
const axios = require("axios");

const app = express();
const PORT = 3000;

/* Set Middleware to Express App */
app.use(express.json());

// Routes
app.post("/handle-webhooks", (req, res) => {
    const body = {"id": "1", "message": "hello"};
    const headers = {
        'Content-Type': "application/json",
    }
    const clientWebhookUrl = "http://localhost:8093/webhook2" // This will be different for each client
    axios.post(clientWebhookUrl, body, {headers})
    return res.sendStatus(200);
})

app.post("/set-webhook", (req,res) => {
    const clientWebhookUrl = req.url;
    // This URL will be saved to database
    return res.sendStatus(200)
}

/* Listen Server */
app.listen(PORT, () => {
    console.log(`App is listening on port ${PORT}.`);
})

Server 2 - My Client 1 Server

Using postman, the Client will make a post request to http://localhost:3000/set-webhook and set the webhook2 endpoint of his web server as a webhook URL to receive a response from my server.

const express = require("express");
const axios = require("axios");

const app = express();
const PORT = 8093;

/* Set Middleware to Express App */
app.use(express.json());

// Routes
app.post("/webhook2", (req, res) => {
    const body = req.body; // receives {"id": "1", "message": "hello"}
    return res.status(200).send(body);
})

/* Listen Server */
app.listen(PORT, () => {
    console.log(`App is listening on port ${PORT}.`);
})

Is the above approach is correct for doing this task? or do I need to add more complex code for this?

Thanks.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda