Skip to content

Installation

UnderDeckLib Installation and Configuration

Section titled “UnderDeckLib Installation and Configuration”

To start using UnderDeckLib in your Node.js project, follow the steps below to install and configure the library.

Make sure you have Node.js (version 16 or higher is recommended) and npm (Node Package Manager) or Yarn installed on your system.

You can install UnderDeckLib using npm or yarn.

Open your terminal at the root of your project and run the following command:

Terminal window
npm install underdecklib

Open your terminal at the root of your project and run the following command:

Terminal window
yarn add underdecklib

2. Importing and Instantiating the Library

Section titled “2. Importing and Instantiating the Library”

After installation, you can import the UnderDeck class into your JavaScript (or TypeScript) files and instantiate it to start using its functionalities.

UnderDeckLib uses ES modules (ESM), so make sure your Node.js project is configured to use modules (for example, by adding "type": "module" to your package.json or by using the .mjs extension for your files).

// Importing the UnderDeck class
import UnderDeck from 'underdecklib';
// Instantiating the library
const client = new UnderDeck();
// Now you can use the methods and properties of the client object
// Example: Authenticate the user
async function authenticate() {
try {
const isAuthenticated = await client.Login("your_username", "your_password");
if (isAuthenticated) {
console.log("User authenticated successfully!");
// Start using other library functionalities
// console.log("My MAC:", await client.GetMyMac());
} else {
console.log("Authentication failed.");
}
} catch (error) {
console.error("Error during authentication:", error);
}
}
authenticate();
// You can also listen for events emitted by the library
client.on("Ready", () => {
console.log("UnderDeckLib is ready for use!");
});
client.on("UndError", (error) => {
console.error("An error occurred in UnderDeckLib:", error);
});
client.on("SocketMessage", (message) => {
console.log("WebSocket message received:", message);
});

UnderDeckLib uses API and WebSocket tokens that are loaded from a credentials.js file (as seen in the code analysis). For production environments or for increased security, you may need to manage these tokens through environment variables or a secure configuration system, instead of hardcoding them directly. Refer to your environment’s documentation for best practices in secret management.

With the library installed and configured, you are ready to explore all the functionalities that UnderDeckLib offers to interact with the UnderDeck ecosystem.