Skip to content

Instantly share code, notes, and snippets.

View calvin-puram's full-sized avatar
🎯
Focusing

Calvin Job Puram calvin-puram

🎯
Focusing
View GitHub Profile
@calvin-puram
calvin-puram / names
Created January 29, 2020 14:43
array of person's name
[
{
"index": NumberInt(0),
"name": "Aurelia Gonzales",
"isActive": false,
"registered": ISODate("2015-02-11T04:22:39+0000"),
"age": NumberInt(20),
"gender": "female",
"eyeColor": "green",
"favoriteFruit": "banana",
[
{
"id": 1,
"title": "Avatar",
"distributor": "20th Century Fox",
"year": 2009,
"amount": "$2,787,965,087",
"img": {
"src": "media/avatar.jpg",
"alt": "avatar"
@calvin-puram
calvin-puram / node_nginx_ssl.md
Created July 12, 2020 13:45 — forked from bradtraversy/node_nginx_ssl.md
Node app deploy with nginx & SSL

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

router.post('/product/:product_id', passportConf.isAuthenticated, (req, res, next) => {
Cart.findOne({owner: req.user._id}, (err, cart) => {
cart.items.push({
item: req.body.product_id,
price: parseFloat(req.body.priceValue),
quantity: parseInt(req.body.quantity)
});
cart.total = (cart.total + parseFloat(req.body.priceValue)).toFixed(2);
Objective: we want to send email to user upon registration welcoming them.
packages to use: nodemailer to send emails https://nodemailer.com/ and mailtrap to trap the messages sent in developement and not sent to the users https://mailtrap.io/
steps:
1 install nodemailer to your nodejs project https://www.npmjs.com/package/nodemailer
2 create a new file in your utils folder
objective: we want to remove the duplicates error we have in our routes i.e in the catch block of every route since they are all thesame we want to create a middleware that will dirrect such errors directely to our global error handler
steps:
1 create a new file may in your utils folder and called it anything
2 we will use this code snippet which is just a middleware that resolve a promise
module.exports = fn => {
return (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
};
3 next we will import this into all our routes and use it like this:
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-addon: cluster-autoscaler.addons.k8s.io
k8s-app: cluster-autoscaler
name: cluster-autoscaler
namespace: kube-system
---
spec:
containers:
- command:
- ./cluster-autoscaler
- --v=4
- --stderrthreshold=info
- --cloud-provider=aws
- --skip-nodes-with-local-storage=false
- --expander=least-waste
# set your EKS cluster name below
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.7.0"
# insert the 21 required variables here
}
module "myapp-vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.7.0"
name = "myapp-vpc"
cidr = var.vpc_cidr_block
private_subnets = var.private_subnets_cidr_blocks
public_subnets = var.public_subnets_cidr_blocks
}