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.
Keep your token secure! Never share it publicly or commit it to version control. Store it in environment variables or secure configuration files.
🚀 Basic Setup
Environment Variables Configuration
Create a .env
file in your project root to store your API token securely:
DISCLOUD_TOKEN=your_api_token_here
Install the dotenv package to load environment variables:
npm install dotenv
Then use it in your application:
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:
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:
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();
Ready to go! You've successfully set up the discloud.app library. Check out Usage Examples to see what you can build!
Last updated