Velo Backend Events

Many Velo modules, including universal modules such as wix-pricing-plans.v2 and backend modules such as wix-media-backend, include events that are triggered when the required conditions are met.

Examples include:

Unlike the frontend, where event handlers are defined in the page code, for backend events, handlers are defined in the events.js backend file.

Add the events.js file as follows:

  1. Hover over the Backend heading in the Public & Backend section of the Code sidebar (Wix Studio) or the Velo sidebar (Wix Editor).
  2. Click the plus icon and then click Handle backend events.

Local IDE:

Create an events.js file in your site repo's src/backend folder in your local IDE with Git integration.

Wix IDE (only available for Wix Studio):

Create an events.js file in the src/backend folder in the Wix IDE.

Defining Backend Event Handlers

To define an event handler in the events.js file, export a function with the name of the Wix module and the name of the event, separated by an underscore.

For example, to handle the onInvoicePaid event from wix-billing-backend, declare the following function in events.js:

Copy
1
export function wixBilling_onInvoicePaid(event) {
2
let invoiceId = event.id.id;
3
let email = event.customer.email;
4
}

To handle the onFileUploaded event from wix-media-backend declare:

Copy
1
export function wixMediaManager_onFileUploaded(event) {
2
let fileName = event.fileInfo.fileName;
3
}

If you have any doubt about how to name the function, there is always sample code in the Velo Reference Docs to show you how to do it.

Notes:

  • Backend events are only triggered for published sites and are not triggered in preview mode.
  • Certain module export formats are not supported in events.js. For more information, see Module Export Syntax.

Testing and Debugging

Backend events are only triggered for published sites and will not work in preview mode. To test an event handler in preview mode, use functional testing. Functional testing saves you time and effort when building your own system for triggering and testing your backend functions, by allowing you to quickly test backend functions directly in the code editor.

For step-by-step instructions on how to test your backend code, see Functional Testing in the Backend.

Velo Package Backend Events

Velo packages are code libraries built with Velo that allow you to add specific functionality to your site, saving you the time you would have spent coding the functionality on your own.

Some Velo packages include backend events, which are contained in their own events.js files. So if you add a Velo package that includes backend events, you might end up with additional events.js files in other locations.

Was this helpful?
Yes
No