Skip to content

Instantly share code, notes, and snippets.

@laurenfazah
laurenfazah / authentication_with_express_postgres.md
Last active Feb 20, 2022
Authentication with an Express API and Postgres
View authentication_with_express_postgres.md

Authentication with an Express API and Postgres

Setting Up

Let's make sure our Express app has the required base modules:

# within root of API
npm install --save express pg knex bcrypt
npm install --save-dev nodemon
@zcaceres
zcaceres / Nested-Routers-Express.md
Last active Jul 18, 2022
Child Routers in Express
View Nested-Routers-Express.md

Nested Routers in Express.js

Express makes it easy to nest routes in your routers. But I always had trouble accessing the request object's .params when you had a long URI with multiple parameters and nested routes.

Let's say you're building routes for a website www.music.com. Music is organized into albums with multiple tracks. Users can click to see a track list. Then they can select a single track and see a sub-page about that specific track.

At our application level, we could first have a Router to handle any requests to our albums.

const express = require('express');
View PokeAPI example Requests.md
@xuwang
xuwang / get-aws-metadata
Last active Jan 7, 2021
Utility script to get commonly used AWS instance metadata (e.g., id, role, account, region, security credentials etc.). Just need curl.
View get-aws-metadata
#!/bin/bash
# Retrieve AWS instrance's commonly used metadata. Require curl.
# ./get-metadata help
# ./get-metadata id
# Input is case insensitive; format to uppper case to generate self-help page.
info=${1^^}
meta_data_url=http://169.254.169.254/latest/meta-data/
roleProfile=$(curl -s http://169.254.169.254/latest/meta-data/iam/info \
| grep -Eo 'instance-profile/([a-zA-Z.-]+)' | sed 's#instance-profile/##')