0

Create a NodeBalancer

by
Published Oct 17, 2025

Creates a NodeBalancer in the requested Region.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Create a NodeBalancer
7
 * Creates a NodeBalancer in the requested Region.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  body: {
13
    client_conn_throttle?: number;
14
    configs?:
15
      | {
16
          algorithm?: "roundrobin" | "leastconn" | "source";
17
          check?: "none" | "connection" | "http" | "http_body";
18
          check_attempts?: number;
19
          check_body?: string;
20
          check_interval?: number;
21
          check_passive?: false | true;
22
          check_path?: string;
23
          check_timeout?: number;
24
          cipher_suite?: string;
25
          id?: number;
26
          nodebalancer_id?: number;
27
          nodes: {
28
            address?: string;
29
            config_id?: number;
30
            id?: number;
31
            label?: string;
32
            mode?: "accept" | "reject" | "drain" | "backup";
33
            nodebalancer_id?: number;
34
            status?: "unknown" | "UP" | "DOWN";
35
            weight?: number;
36
          }[];
37
          nodes_status?: { down?: number; up?: number };
38
          port?: number;
39
          protocol?: "tcp";
40
          proxy_protocol?: "none" | "v1" | "v2";
41
          ssl_cert?: string;
42
          ssl_commonname?: string;
43
          ssl_fingerprint?: string;
44
          ssl_key?: string;
45
          stickiness?: "none" | "table";
46
        }
47
      | {
48
          algorithm?: "roundrobin" | "leastconn" | "source";
49
          check?: "none" | "connection" | "http" | "http_body";
50
          check_attempts?: number;
51
          check_body?: string;
52
          check_interval?: number;
53
          check_passive?: false | true;
54
          check_path?: string;
55
          check_timeout?: number;
56
          cipher_suite?: string;
57
          id?: number;
58
          nodebalancer_id?: number;
59
          nodes: {
60
            address?: string;
61
            config_id?: number;
62
            id?: number;
63
            label?: string;
64
            mode?: "accept" | "reject" | "drain" | "backup";
65
            nodebalancer_id?: number;
66
            status?: "unknown" | "UP" | "DOWN";
67
            weight?: number;
68
          }[];
69
          nodes_status?: { down?: number; up?: number };
70
          port?: number;
71
          protocol?: "http";
72
          proxy_protocol?: string;
73
          ssl_cert?: string;
74
          ssl_commonname?: string;
75
          ssl_fingerprint?: string;
76
          ssl_key?: string;
77
          stickiness?: "none" | "table" | "http_cookie";
78
        }
79
      | {
80
          algorithm?: "roundrobin" | "leastconn" | "source";
81
          check?: "none" | "connection" | "http" | "http_body";
82
          check_attempts?: number;
83
          check_body?: string;
84
          check_interval?: number;
85
          check_passive?: false | true;
86
          check_path?: string;
87
          check_timeout?: number;
88
          cipher_suite?: "recommended" | "legacy";
89
          id?: number;
90
          nodebalancer_id?: number;
91
          nodes: {
92
            address?: string;
93
            config_id?: number;
94
            id?: number;
95
            label?: string;
96
            mode?: "accept" | "reject" | "drain" | "backup";
97
            nodebalancer_id?: number;
98
            status?: "unknown" | "UP" | "DOWN";
99
            weight?: number;
100
          }[];
101
          nodes_status?: { down?: number; up?: number };
102
          port?: number;
103
          protocol?: "https";
104
          proxy_protocol?: string;
105
          ssl_cert?: string;
106
          ssl_commonname?: string;
107
          ssl_fingerprint?: string;
108
          ssl_key?: string;
109
          stickiness?: "none" | "table" | "http_cookie";
110
        }[];
111
    firewall_id?: number;
112
    label?: string;
113
    region: string;
114
    tags?: string[];
115
  },
116
) {
117
  const url = new URL(`https://api.linode.com/${apiVersion}/nodebalancers`);
118

119
  const response = await fetch(url, {
120
    method: "POST",
121
    headers: {
122
      "Content-Type": "application/json",
123
      Authorization: "Bearer " + auth.token,
124
    },
125
    body: JSON.stringify(body),
126
  });
127
  if (!response.ok) {
128
    const text = await response.text();
129
    throw new Error(`${response.status} ${text}`);
130
  }
131
  return await response.json();
132
}
133