Define Backend Event Handlers

You can define backend event handlers in the events.js backend file.

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 and then click Handle backend events.

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. The function name should consist of the Wix module and the name of the event, separated by an underscore. You can visit the documentation 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:

Copy

Step 3 | Test and debug your function

There are two ways to test your backend event handlers:

  • In preview mode, use functional testing to call your event handler function manually.
  • Publish your site, then trigger the event that activates your event handler.
Was this helpful?
Yes
No