Resend + NextJs 14 API

index.ts
import { NextResponse } from "next/server";
import { Resend } from "resend";

type RequestBody = {
  username: string;
  email: string;
  message: string;
};

export async function POST(request: Request) {
  const requestBody: RequestBody = await request.json();
  const { username, email, message } = requestBody;
  const resend = new Resend(process.env.RESEND_API_KEY);

  return await resend.emails
    .send({
      from: "me@email.com",
      to: "other@email.com",
      subject: `Subject of the email`,
      text: `This text could be something really cool.`,
    })
    .then((result) => {
      if (!result.data?.id) {
        return NextResponse.json({ status: "Error" }, { status: 500 });
      }

      return NextResponse.json({ status: "Sent" }, { status: 200 });
    })
    .catch((error) =>
      NextResponse.json({ status: "Internal error", error: error }, { status: 500 })
    );
}

Resend + NodeJS (usually for back-end applications)

index.ts
import { Resend } from 'resend';
const resend = new Resend('re_123456789');

await resend.emails.send({
  from: 'you@example.com',
  to: 'user@gmail.com',
  subject: 'hello world',
  text: 'it works!',
});

Resend + NodeJS + HTML

index.ts
await resend.emails.send({
  from: 'you@example.com',
  to: 'user@gmail.com',
  subject: 'hello world',
  html: '<strong>it works!</strong>',
});