CloudNexus SDK Reference

Official client library for interacting with the CloudNexus Cloud Infrastructure API. Supports Node.js 16+, Deno, and modern browsers.

📦 Package Health Stable TypeScript Native Tree-shakeable

The CloudNexus SDK provides a type-safe, async-first interface to provision, manage, and scale cloud resources. All API methods return promises and support both callback and async/await patterns.

Installation

Install the SDK using your preferred package manager:

bash
# Using npm npm install @cloudnexus/sdk # Using yarn yarn add @cloudnexus/sdk # Using pnpm pnpm add @cloudnexus/sdk

For Deno, import directly from the CDN:

typescript
import { CloudNexus } from "https://cdn.cloudnexus.dev/sdk/v3/mod.ts";

Authentication

The SDK uses API keys for authentication. Create keys in the CloudNexus Console under Settings → API Keys.

typescript
import { CloudNexus } from "@cloudnexus/sdk"; // Recommended: Use environment variables const client = new CloudNexus({ apiKey: process.env.CN_API_KEY, region: "us-east-1", // Optional: defaults to nearest timeout: 30000, // ms retries: 3 });
⚠️ Security Notice Never commit API keys to version control. Use dotenv or your environment's secret management system.

Quick Start

Provision a compute instance and attach persistent storage in under 50 lines:

typescript
async function deployWorkload() { // 1. Create compute instance const vm = await client.compute.create({ name: "prod-api-node", type: "cn-standard-4", image: "ubuntu-22.04-lts", region: "eu-west-2", tags: ["production", "api"] }); // 2. Attach block storage await client.storage.attach({ instanceId: vm.id, volume: { size: 100, type: "nvme-ssd" } }); // 3. Configure firewall rules await client.network.firewall.createRules(vm.id, [ { port: 443, protocol: "tcp", source: "0.0.0.0/0" }, { port: 22, protocol: "tcp", source: "10.0.0.0/8" } ]); console.log(`✅ Deployed: ${vm.publicIp}`); }

Compute & VMs

client.compute.create(options)

Provisions a new virtual machine or bare-metal server.

ParameterTypeDescription
name RequiredstringUnique identifier for the instance
type RequiredstringInstance family: cn-standard, cn-memory, cn-gpu
image RequiredstringOS template ID or name
regionstringTarget deployment region
tagsstring[]Metadata tags for filtering

Returns: Promise<InstanceResource>

Error Handling

The SDK throws typed errors for all API failures. Wrap calls in try/catch blocks:

typescript
try { const vm = await client.compute.create({ name: "test" }); } catch (error) { if (error instanceof CloudNexusError) { console.error(`Code: ${error.code} | Status: ${error.statusCode}`); console.error(`Message: ${error.message}`); console.error(`Retry After: ${error.retryAfter}`); } }
CodeStatusMeaning
QUOTA_EXCEEDED429Rate limit or resource quota reached
AUTH_FAILED401Invalid or expired API key
INVALID_REGION400Specified region does not exist
SERVICE_UNAVAILABLE503Temporary backend degradation

Configuration

Advanced runtime options can be passed during initialization:

typescript
const client = new CloudNexus({ apiKey: process.env.CN_API_KEY, // Request configuration timeout: 45000, retries: 5, retryStrategy: "exponential", // "exponential" | "linear" // Feature flags enableTelemetry: false, disableAutoScaling: false, // Custom HTTP agent (Node.js only) httpAgent: new https.Agent({ keepAlive: true }) });