1.4.2 ⢠Published 6 months ago
@modexvpn/hcloud v1.4.2
@modexvpn/hcloud
A clean, type-safe SDK for the Hetzner Cloud API using Node.js, TypeScript, and Zod.
Features
- š Zod-powered runtime validation ā fully JavaScript-safe
- š§ Fully type-safe using TypeScript with
z.infer<>and enums - š Modular structure:
hcloud.servers.list(),hcloud.locations.getById() - ā ļø Centralized error handling with
formatHcloudError() - āļø Axios-based HTTP client with auto-authentication
- š ESM and CommonJS compatible
- šļø Clean folder structure for scalability and maintainability
SDK Status
This SDK is stable, but not yet feature-complete.
We're already on v1.x and will maintain backward compatibility.
Any breaking changes will be released as v2.0.0.
š What's New in v1.4
createSSHKey(options)ā Create a new SSH keygetSSHKeys()ā List all SSH keysgetSSHKey(id)ā Get a single SSH key by IDupdateSSHKey(id, options)ā Update an existing SSH keydeleteSSHKey(id)ā Delete an SSH key
āļø Usage Examples
Create SSH Key
const sshKey = await hcloud.security.createSSHKey({
name: "modex-prod-key",
public_key: "ssh-ed25519 AAAAC3N...",
labels: { environment: "prod" }
})List SSH Keys
const allKeys = await hcloud.security.listSSHKeys()Get SSH Key by ID
const key = await hcloud.security.getSSHKey(12345)Update SSH Key
const updated = await hcloud.security.updateSSHKey(12345, {
name: "modex-updated-key",
labels: { updated: "true" }
})Delete SSH Key
await hcloud.security.deleteSSHKey(12345)š Installation
npm install @modexvpn/hcloudš§ Usage
List all servers
import { hcloud } from '@modexvpn/hcloud'
const servers = await hcloud.servers.list()Get a single server by ID
const server = await hcloud.servers.getById(123456)Fetch server metrics
const metrics = await hcloud.servers.getMetrics(123456)Power control
await hcloud.servers.powerControl.off(123456)
await hcloud.servers.powerControl.reboot(123456)
await hcloud.servers.powerControl.on(123456)
await hcloud.servers.powerControl.reset(123456)
await hcloud.servers.powerControl.shutdown(123456)Create a server
await hcloud.servers.create({
name: 'test-server',
server_type: 'cx21',
image: 'ubuntu-22.04',
location: 'nbg1',
ssh_keys: ['ssh-key-id'],
})Delete a server
await hcloud.servers.delete(123456)SSH Into Server
const { stdout } = await sshIntoServer("192.168.1.100", "apt update && apt upgrade -y", "root")
console.log(stdout)š” Requires
SSH_PRIVATE_KEYin your environment
š¢ Environment Setup
Create a .env file and add your Hetzner API token:
HCLOUD_API_TOKEN=your-token-hereš Project Structure
@modexvpn/hcloud
āāā client.ts
āāā index.ts
āāā sdk/
ā āāā servers/
ā ā āāā actions/
ā ā ā āāā sshIntoServer.ts
ā ā āāā createServer.ts
ā ā āāā server-type/
ā ā āāā getServerTypes.ts
ā ā āāā getServerType.ts
ā ā āāā index.ts
ā āāā locations/
ā āāā datacenters/
ā āāā getDatacenters.ts
ā āāā getDatacenter.ts
āāā types/
ā āāā common/
ā āāā enums/
ā āāā errors/
ā āāā ...
āāā utils/
ā āāā formatError.ts
āāā tsconfig.json
āāā tsup.config.ts
āāā README.mdš« API Coverage
Core Resources
Security
Storage & Networking
Firewalls & IPs
Load Balancers
Billing
š Contributing
PRs welcome! Please follow the existing structure and run:
npm run lint
npm run buildš Resources
š License
MIT Ā© 2025 MODEX