Skip to content

Instantly share code, notes, and snippets.

@abdamin
abdamin / index.js
Created April 12, 2020 07:51
index.js file for the step by step guide to manage environment variables in nodejs using dotenv
const express = require("express");
const app = express();
const dotenv = require("dotenv");
dotenv.config();
const MY_PORT = process.env.PORT;
const MY_APP_SECRET = process.env.APP_SECRET;
app.get("/", (req, res) => {
return res.send(MY_APP_SECRET);
@abdamin
abdamin / package.json
Created April 12, 2020 06:52
Package.json for the Step by Step guide to setup environment variables in Node App using dotenv
{
"name": "dotenv-node-tutorial",
"version": "1.0.0",
"description": "A step by step guide to set up environment variables in your NodeJS Application using dotenv",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"repository": {
"type": "git",
@abdamin
abdamin / main.js
Created November 16, 2019 10:45
JS file for the client of the serverless tutorial application
//post request URL
const URL = "http://localhost:9000/sendEmail";
//function to make a post request to lambda function using the fetch API
const sendEmail = async (url, data = {}) => {
// Default options are marked with *
const response = await fetch(url, {
method: "POST",
body: JSON.stringify(data)
});
@abdamin
abdamin / index.html
Created November 16, 2019 10:28
HTML File for the Client in the serverless tutorial
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
@abdamin
abdamin / sendEmail.js
Last active November 16, 2019 09:56
Send Email lambda function after adding sendgrid integration
exports.handler = function(event, context, callback) {
//import sendgrid mail npm package
const sgMail = require("@sendgrid/mail");
//only listen to POST requests
if (event.httpMethod === "POST") {
//set sendgrid API Key which you created on the dashboard under settings
sgMail.setApiKey(
"YOUR_SENDGRID_API_KEY"
);
@abdamin
abdamin / sendEmail.js
Created November 16, 2019 07:40
sendEmail lambda function initially after adding error checking to make sure its serves POST requests and specified path only
exports.handler = function(event, context, callback) {
//only listen to POST requests
if (event.httpMethod === "POST") {
callback(null, {
statusCode: 200,
body: "Hello Abdullah"
});
} else {
callback(null, {
@abdamin
abdamin / netlify.toml
Created November 16, 2019 05:14
netlify.toml file for the serverless application to tutorial to process payments
[build]
functions = "lambda"
@abdamin
abdamin / package.json
Last active November 18, 2019 07:55
Package.json File After Netlify-Lambda serve and install script setup for the Server-less App Tutorial
{
"name": "netlify_services_aws_lambda_tutorial",
"version": "1.0.0",
"description": "A tutorial to setup a serverless application that accepts payments using AWS lambda functions with Netlify",
"main": "index.js",
"scripts": {
"lambda-serve": "netlify-lambda serve functions",
"lambda-build": "netlify-lambda build functions"
},
"repository": {
@abdamin
abdamin / index.js
Created October 24, 2019 10:10
index.js after adding checkCache middleware function
//set up dependencies
const express = require("express");
const redis = require("redis");
const axios = require("axios");
const bodyParser = require("body-parser");
//setup port constants
const port_redis = process.env.PORT || 6379;
const port = process.env.PORT || 5000;
@abdamin
abdamin / index.js
Created October 24, 2019 09:49
index.js after adding redis setex
//set up dependencies
const express = require("express");
const redis = require("redis");
const axios = require("axios");
const bodyParser = require("body-parser");
//setup port constants
const port_redis = process.env.PORT || 6379;
const port = process.env.PORT || 5000;