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:

Wix Editor:

Hover over the Backend heading in the Code Files section of the Velo Sidebar and click the plus icon plus icon.

Add events.js

Wix IDE (Wix Studio):

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

Local IDE (Wix Editor or Wix Studio):

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

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 Code
export function wixBilling_onInvoicePaid(event) {
let invoiceId = event.id.id;
let email = event.customer.email;
}

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

Copy Code
export function wixMediaManager_onFileUploaded(event) {
let fileName = event.fileInfo.fileName;
}

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 (Wix Editor)

Note: Functional testing is note yet available in Wix Studio.

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 panel.

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