Skip to content

Instantly share code, notes, and snippets.

View rishavk1102's full-sized avatar
🏠
Working from home

Rishav Kumar rishavk1102

🏠
Working from home
View GitHub Profile
@rishavk1102
rishavk1102 / index.js
Created December 9, 2023 11:30
Boiler Plate NodeJS Server
const express = require("express");
const app = express();
let port = process.env.PORT || 3000;
app.route('/')
.get((req, res) => {
console.log(req.body);
res.sendStatus(200);
@rishavk1102
rishavk1102 / index.js
Last active December 9, 2023 11:13
Simple code to send an email using SendGrid with attachments
const express = require("express");
const mail = require("@sendgrid/mail");
const app = express();
// It is highly recommended to store the API Keys in a seperate file and DO NOT check it in Git
mail.setApiKey("__sendgrid_api_key__");
app.post('/email/send', (req, res) => {
let {
@rishavk1102
rishavk1102 / request.json
Created October 1, 2023 15:01
Sample request for calling the SendGrid API
{
"from": {
"name": "Rishav",
"email": "hi@whoisrishav.com"
},
"to": [
"rishav@domain.com",
"rishav@domain1.com"
],
"cc": [
@rishavk1102
rishavk1102 / index.js
Last active October 1, 2023 11:58
Code to send emails with HTML Body using NodeJS and SendGrid
const express = require("express");
const mail = require("@sendgrid/mail");
const app = express();
// It is highly recommended to store the API Keys in a seperate file and DO NOT check it in Git
mail.setApiKey("__sendgrid_api_key__");
app.post('/email/send', (req, res) => {
// Any 1 of to, cc or bcc are required to successfully send an email.
@rishavk1102
rishavk1102 / index.js
Last active October 1, 2023 11:58
Code to send emails using NodeJS and SendGrid
const express = require("express");
const mail = require("@sendgrid/mail");
const app = express();
// It is highly recommended to store the API Keys in a seperate file and DO NOT check it in Git
mail.setApiKey("__sendgrid_api_key__");
app.post('/email/send', (req, res) => {
// Any 1 of to, cc or bcc are required to successfully send an email.
@rishavk1102
rishavk1102 / commands.sh
Created October 1, 2023 09:20
Commands to run to create a project compatible with sending emails from NodeJS using SendGrid
mkdir [project_name]
cd [project_name]
npm init -y
touch index.js
npm i express @sendgrid/mail
npm i nodemon –save-dev
code .
@rishavk1102
rishavk1102 / commands.sh
Created September 21, 2023 13:09
Commands to create a new NodeJS project
mkdir [project_name]
cd [project_name]
npm init -y
touch index.js
npm i express multer
npm i nodemon --save-dev
code .
@rishavk1102
rishavk1102 / index.js
Last active September 20, 2023 14:27
Basic code to receive emails from SendGrid and display the email content.
const express = require('express')
const multer = require('multer')
const app = express()
const upload = multer()
app.post('/api/parse', upload.any(), async (req, res) => {
const body = req.body