0

Create a node

by
Published Oct 17, 2025

Creates a NodeBalancer node, a backend that can accept traffic for this NodeBalancer Config.

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 node
7
 * Creates a NodeBalancer node, a backend that can accept traffic for this NodeBalancer Config.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  nodeBalancerId: string,
13
  configId: string,
14
  body: {
15
    address?: string;
16
    config_id?: number;
17
    id?: number;
18
    label?: string;
19
    mode?: "accept" | "reject" | "drain" | "backup";
20
    nodebalancer_id?: number;
21
    status?: "unknown" | "UP" | "DOWN";
22
    weight?: number;
23
  },
24
) {
25
  const url = new URL(
26
    `https://api.linode.com/${apiVersion}/nodebalancers/${nodeBalancerId}/configs/${configId}/nodes`,
27
  );
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43