# How to write a webhook in gitea in node.js / javascript

**URL:** <https://forum.gitea.com/t/how-to-write-a-webhook-in-gitea-in-node-js-javascript/1907>\
**Category:** General\
**Created:** [February 8, 2020, 8:44pm UTC](https://forum.gitea.com/t/how-to-write-a-webhook-in-gitea-in-node-js-javascript/1907 "2020-02-08T20:44:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adeel](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@adeel](https://forum.gitea.com/u/adeel)\
**Post date:** [February 8, 2020, 8:44pm UTC](https://forum.gitea.com/t/how-to-write-a-webhook-in-gitea-in-node-js-javascript/1907/1 "2020-02-08T20:44:47Z")

</div>

Below is an example written using node.js

```
const express = require('express')
const crypto = require('crypto')
const bodyParser = require('body-parser')
const SECRET = 'HELLO_SECRET'

const port = 9000
const app = express()

const options = {
    inflate: true,
    limit: '100kb',
    type: 'application/json',
}
app.use(bodyParser.raw(options))

app.get('/', (req, res) => res.send('git-hooks'))

app.post('/', (req, res) => {
    const signature = req.headers['x-gitea-signature']
    if (!signature) {
        console.error('x-gitea-signature missing')
        return res.send()
    }

    const hmac = crypto.createHmac('sha256', SECRET)
    hmac.update(req.body)

    const payload_signature = hmac.digest('hex')
    if (signature !== payload_signature) {
        console.error('signature !== payload_signature')
        return res.send()
    }

    const json = JSON.parse(req.body.toString())
    console.log('json')
    console.log(json)
    
    // SIGNATURES MATCHES, do your thing here.
    
    res.send('success')
})

app.listen(port, () => console.log(`git-hooks app running on ${port}`))

```
