GithubHelp home page GithubHelp logo

resend-node-example's Introduction

Resend with Node.js

This example shows how to use Resend with Node.js.

Prerequisites

To get the most out of this guide, you’ll need to:

Instructions

  1. Replace re_123456789 on index.ts with your API key.

  2. Install dependencies:

npm install
# or
yarn
  1. Execute the following command:
npm run dev

License

MIT License

resend-node-example's People

Contributors

renovate[bot] avatar zenorocha avatar dependabot[bot] avatar jayanratna avatar

Stargazers

Damian Janus avatar Miguel Silva avatar Lázaro Manuel Cunga avatar Mustafa Ahmed avatar Evance Osoo avatar Sahil Hussain. avatar Adriano Monecchi avatar Valéria Padilha de Vargas avatar Timi  avatar Náyeli Gómez avatar Jonathan Engelsma avatar Jérémy avatar Rafael avatar Martin Wagenführ avatar netop://ウエハ avatar Walisson Gomes avatar Harith Iqbal avatar  avatar Alejandro D. Arzola Saavedra avatar Edward Brito Diaz avatar Kennedy Anyidoho avatar  avatar  avatar Omar Imam avatar laiso avatar Dipak Savaliya avatar Hebert  F. Barros avatar Philippe Woodruff avatar Priyam Raj avatar  avatar Rohan Sharma avatar Lois avatar

Watchers

 avatar

resend-node-example's Issues

Bug: Resend not working with node v16

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 <[email protected]>',
            to: ['[email protected]'],
            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.

Defaulting to localhost:3001 when deployed to firebase functions

Hey guys! Loving the dev experience using resend but I came across some weird behaviour.

I tested resend locally and within the firebase emulators and it sends fine. However, when I deploy to firebase functions (2nd gen), I get this axios error when calling resend.sendEmail and for some reason the baseUrl has been switched to localhost:3001.

Any Ideas?

Error:

AxiosError: connect ECONNREFUSED 127.0.0.1:3001
    at Function.AxiosError.from (/workspace/node_modules/axios/dist/node/axios.cjs:836:14)
    at RedirectableRequest.handleRequestError (/workspace/node_modules/axios/dist/node/axios.cjs:3010:25)
    at RedirectableRequest.emit (node:events:513:28)
    at RedirectableRequest.emit (node:domain:489:12)
    at ClientRequest.eventHandlers.<computed> (/workspace/node_modules/follow-redirects/index.js:14:24)
    at ClientRequest.emit (node:events:513:28)
    at ClientRequest.emit (node:domain:489:12)
    at Socket.socketErrorListener (node:_http_client:494:9)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12) {
  port: 3001,
  address: '127.0.0.1',
  syscall: 'connect',
  code: 'ECONNREFUSED',
  errno: -111,
  config: {
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    adapter: [ 'xhr', 'http' ],
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: Infinity,
    maxBodyLength: Infinity,
    env: { FormData: [Function], Blob: null },
    validateStatus: [Function: validateStatus],
    headers: AxiosHeaders {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      Authorization: 'Bearer re_BbYfmi5q_2wh2VCQMhyEpwFHq1hXp67vw',
      'User-Agent': 'node:0.15.4',
      'Content-Length': '9784',
      'Accept-Encoding': 'gzip, compress, deflate, br'
    },
    baseURL: 'http://localhost:3001',
    method: 'post',
    url: 'http://localhost:3001/email',
    data: `{"from":"[email protected]","to":"[email protected]","subject":"You're on the waitlist!","html":"<!DOCTYPE html PUBLIC \\"-//W3C//DTD XHTML 1.0 Transitional//EN\\" \\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\\"><html lang=\\"en\\"><head data-id=\\"__react-email-head\\"><meta http-equiv=\\"Content-Type\\" content=\\"text/html; charset=UTF-8\\"/></head><div id=\\"__react-email-preview\\" style=\\"display:none;overflow:hidden;line-height:1px;opacity:0;max-height:0;max-width:0\\">The wait has begun!<div> ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏… [message truncated due to size]

issue with angular 16

Hello All

i try to use resend with angular 16 , but i get the errors down . i try it only with node in index.ts it works fine .

error TS7016: Could not find a declaration file for modulile for module 'react'. 'D:/@@@DEV/apps/@@engel/engmatool/node_modules/react/index.js' implicitly has an 'any' type.
[ng] Try npm i --save-dev @types/react if it exists or add a new declaration (.d.ts) file containing declare module 'react';
[ng]
[ng] 2 import * as React from 'react';
[ng] ~~~~~~~

[ng] × Failed to compile.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • resend ^3.0.0
  • @types/node ^20.2.5
  • ts-node ^10.9.1
  • typescript ^5.1.3

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.