Simple Sendgrid Example using Node


Here is a very simple example of how to create a simple Sendgrid app using NodeJS.

Change directory into your node app.

cd /name/of/node/app

Install Sendgrid using Node Package Manager.

npm i sendgrid

Use your Sendgrid username and password to send an email.

var sendgrid  = require('sendgrid')(process.env.SENDGRID_USERNAME, process.env.SENDGRID_PASSWORD);

exports.send = function(req, res, next){ 
    if(req.method == "POST"){
        var SENDGRID = {
            USER: "<<username>>", 
            KEY:  "<<key>>", 
            TO:   "<< Add Custom email>>", 
            FROM: "" 
            to      : SENDGRID.TO,
            from    : SENDGRID.FROM,
            subject : 'Feedback',
            text    : JSON.stringify(req.body)
        function(err, json) {
            if (err) { return console.error(err); }
        console.log("routes/index:", 'feedback');