resend / resend-node-example

This example shows how to use Resend with Node.js
MIT License
42 stars 14 forks source link

Bug: Resend not working with node v16 #20

Open krshashwat opened 6 months ago

krshashwat commented 6 months ago

Issue

When i am using node v16 then it is throwing an error - ReferenceError: Headers is not defined

How to reproduce

use node version - v16.20.2

Code snippet

require('dotenv').config();
const { Resend } = require('resend');
const express = require('express');

const resend = new Resend(process.env.EMAIL_API_KEY);

const app = express();

app.get('/', async (req, res) => {
    try {
        const data = await resend.emails.send({
            from: 'Acme <onboarding@resend.dev>',
            to: ['kumarshashwat62@gmail.com'],
            subject: 'Hello World',
            html: '<strong>It works!</strong>'
        });
        console.log(data);
        res.status(200).json({ msg: 'email sent' });
    } catch (err) {
        console.log(err);
        res.status(400).json({ msg: 'email not sent' });
    }
});

const PORT = process.env.PORT || 8000;
app.listen(PORT, () => console.log('Server running on Port - ' + PORT));

Error Screenshot

image

Alternative Fix

I updated the node version to 18.13.0 and it worked.