> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt ## Resource: Define Backend Event Handlers ## Article: Define Backend Event Handlers ## Article Link: https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/backend-code/events/define-backend-event-handlers.md ## Article Content: # Define Backend Event Handlers You can define [backend event](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/backend-code/events/about-backend-events.md) handlers in the `events.js` backend file. > **Note**: When developing websites, you can only handle events using Velo. Handling site events using the JavaScript SDK [isn't currently supported](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/develop-with-the-sdk/velo-to-sdk-api-mapping.md#velo-apis-you-should-continue-to-use). ## Step 1 | Add an `events.js` backend file The way that you add an `events.js` file to the backend depends on which IDE you're using. ### Editor 1. Hover over **Backend** in the **Public & Backend** section of the code sidebar. 2. Click the **More Actions** icon ![plus icon](https://wixmp-833713b177cebf373f611808.wixmp.com/images/e45800424595befdc6fe5931a1b7c0b4.png) and then click **Handle backend events**. ![Add events.js](https://wixmp-833713b177cebf373f611808.wixmp.com/images/a1fac75ac6a2e949a10e8098f84d04ea.png) ### Wix IDE or your local IDE Add an `events.js` file to the `src/backend` folder. ## Step 2 | Define a backend event handler To define an event handler in the `events.js` file, export a function using a [supported export syntax](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/java-script-velo/module-export-syntax.md). The function name should consist of the Wix module and the name of the event, separated by an underscore. Check the **Events** subcategory in most APIs in the [API documentation](https://dev.wix.com/docs/velo.md) to confirm the exact function naming and to see what information is passed to the event handler when it is called. Here is an example of an event handler that [triggers when an invoice is paid](https://dev.wix.com/docs/velo/apis/wix-billing-backend/events/on-invoice-paid.md): ```javascript export function wixBilling_onInvoicePaid(event) { const invoiceId = event.id.id; const email = event.customer.email; // Add your own logic here. } ``` ## Step 3 | Test and debug your function There are two ways to [test your backend event handlers](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/backend-code/events/about-backend-events.md#testing-and-debugging): + In preview mode, use [functional testing](https://dev.wix.com/docs/develop-websites/articles/workspace-tools/testing-monitoring/functional-testing/test-backend-functions-with-functional-testing.md) to call your event handler function manually. + Publish your site, then trigger the event that activates your event handler. Watch a demo of how to set up backend event handlers: `youtube:https://youtu.be/-LAtdo0mbiY?t=162`