-
Notifications
You must be signed in to change notification settings - Fork 0
Event Handling
kkMihai edited this page Jan 21, 2024
·
2 revisions
The VirtualizorClient
class extends the EventEmitter
class in Node.js, allowing you to handle various events that occur during the interaction with the Virtualizor API.
-
Description: Attaches an event listener to the
VirtualizorClient
instance. -
Parameters:
-
event
- The event to listen to. -
callback
- The callback function to execute when the event is triggered.
-
const Client = new VirtualizorClient(options)
- Description: Triggered when a new virtual server is successfully created.
- Example:
Client.on('vpsCreated', (response) => {
console.log(`Virtual Server Created! Details:`, response);
});
- Description: Triggered when a virtual server is successfully started.
- Example:
Client.on('vpsStarted', (response) => {
console.log(`Virtual Server Started! Details:`, response);
});
- Description: Triggered when a virtual server is successfully stopped.
- Example:
Client.on('vpsStopped', (response) => {
console.log(`Virtual Server Stopped! Details:`, response);
});
- Description: Triggered when a virtual server is successfully restarted.
- Example:
Client.on('vpsRestarted', (response) => {
console.log(`Virtual Server Restarted! Details:`, response);
});
- Import the
VirtualizorClient
class. - Create an instance named
Client
with the necessary configuration (host, port, API key, API pass). - If you need to perform specific actions, destructure the required methods from the
Client
instance. - Attach event listeners to the
Client
instance using theon
method (Client.on('event', callback)
).