Getting Started

Learn how to install, configure, and start using the discloud.app NPM library to manager your Discloud application.

📦 Installation

You can install the discloud.app library using your preferred package manager:

npm install discloud.app

🔑 Obtaining Your API Token

Before using the library, you need to obtain your Discloud API Token.

For detailed instructions on how to get your API token, please visit here.

🚀 Basic Setup

Environment Variables Configuration

1

Create a .env file in your project root to store your API token securely:

.env
DISCLOUD_TOKEN=your_api_token_here
2

Install the dotenv package to load environment variables:

npm install dotenv
3

Then use it in your application:

index.js
require("dotenv").config(); // Load environment variables
const { discloud } = require("discloud.app");

async function main() {
  try {
    // Authenticate using environment variable
    await discloud.login(process.env.DISCLOUD_TOKEN);
    console.log("Successfully authenticated with Discloud!");

    // Your application logic here...
  } catch (error) {
    console.error("Authentication failed:", error.message);
  }
}

main();

🎯 Your First API Call

Let's test the connection by fetching information about your applications:

test-connection.js
require("dotenv").config(); // Load environment variables
const { discloud } = require("discloud.app");

async function testConnection() {
  try {
    // Authenticate
    await discloud.login(process.env.DISCLOUD_TOKEN);

    // Fetch all your applications
    const apps = await discloud.apps.fetch("all");

    console.log(`Found ${apps.size} applications:`);
    apps.forEach((app, id) => {
      console.log(`- ${app.name} (ID: ${id})`);
    });
  } catch (error) {
    console.error("Error:", error.message);
  }
}

testConnection();

📁 TypeScript Support

The library includes full TypeScript support with type definitions:

index.ts
import "dotenv/config"; // Load environment variables
import { discloud, App } from "discloud.app";

async function main(): Promise<void> {
  try {
    await discloud.login(process.env.DISCLOUD_TOKEN!);

    // Fetch a specific application with full type support
    const app: App = await discloud.apps.fetch("your_app_id");

    console.log(`App: ${app.name}`);
    console.log(`Status: ${app.online ? "Online" : "Offline"}`);
    console.log(`RAM: ${app.ram}MB`);
  } catch (error) {
    console.error("Error:", error);
  }
}

main();

Last updated