Skip to content
GitHubXDiscordRSS

DnsRecords

Learn how to create, update, and manage Cloudflare DNS Records for your domains using Alchemy.

Manages DNS records in a Cloudflare zone using the Cloudflare DNS API.

Create a basic A record pointing to an IP address.

import { DnsRecords } from "alchemy/cloudflare";
const records = await DnsRecords("example-dns", {
zoneId: "YOUR_ZONE_ID",
records: [
{
name: "www.example.com",
type: "A",
content: "192.0.2.1",
proxied: true,
},
],
});

Create MX and TXT records for email routing.

import { DnsRecords } from "alchemy/cloudflare";
const emailRecords = await DnsRecords("email-dns", {
zoneId: "YOUR_ZONE_ID",
records: [
{
name: "example.com",
type: "MX",
content: "aspmx.l.google.com",
priority: 1,
},
{
name: "example.com",
type: "TXT",
content: "v=spf1 include:_spf.google.com ~all",
},
],
});

Use delete: false to prevent DNS records from being deleted when the resource is removed from Alchemy. This is useful for critical DNS records that should persist even if their Alchemy configuration is removed.

import { DnsRecords } from "alchemy/cloudflare";
const records = await DnsRecords("critical-dns", {
zoneId: "YOUR_ZONE_ID",
delete: false,
records: [
{
name: "example.com",
type: "MX",
content: "aspmx.l.google.com",
priority: 1,
},
{
name: "example.com",
type: "TXT",
content: "v=spf1 include:_spf.google.com ~all",
},
],
});

Create proxied records to take advantage of Cloudflare’s CDN and security features.

import { DnsRecords } from "alchemy/cloudflare";
const proxiedRecords = await DnsRecords("proxied-dns", {
zoneId: "YOUR_ZONE_ID",
records: [
{
name: "www.example.com",
type: "A",
content: "192.0.2.1",
proxied: true,
ttl: 1, // Auto TTL when proxied
},
{
name: "blog.example.com",
type: "CNAME",
content: "www.example.com",
proxied: true,
},
],
});