Skip to content

Instantly share code, notes, and snippets.

import dotenv from "dotenv";
import pg from "pg";
dotenv.config();
console.log({ url: process.env.DATABASE_URL });
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
pool.on("error", (err) => console.error(err));
export default pool;
FROM node:19.4.0-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
import express from "express";
const userRouter = express.Router();
userRouter.route("/me").get((req, res) => {
res.status(200).send("You are you!");
});
export default userRouter;
import express, { Express, Request, Response } from "express";
import dotenv from "dotenv";
import userRouter from "./user";
dotenv.config();
const app: Express = express();
const port = process.env.PORT || 3000;
app.use(json());
{
"db": {
"connectionString": "postgresql://admin:admin1pass@localhost:5432/ecommerce"
},
"outdir": "./schema"
}
@christopherbauer
christopherbauer / init-db.sql
Created July 1, 2023 03:27
Postgres initdb
CREATE DATABASE ecommerce;
\c ecommerce;
-- Create the User table
CREATE TABLE "User" (
user_id SERIAL PRIMARY KEY,
email VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL
);
import logger from "../logger";
export const Graceful = (errorMessage: string) => {
return function captural(
originalMethod: Function,
_context: ClassMethodDecoratorContext
) {
function ReplacementMethod(this: any, ...args: any[]) {
try {
const result = originalMethod.call(this, ...args);
import { User } from "./DataAccessLayer";
import { LogCall } from "./logCall";
import { Retry } from "./retry";
export type Action = "Click" | "Submit" | "Redirect";
function randomIntInclusive(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
export class MetricTracking {
/**
* This method attempts to mark a user action in the metric tracking service. It retries 3x over the course of 5 seconds
import logger from "../logger";
export const LogCall = (
originalMethod: Function,
context: ClassMethodDecoratorContext
) => {
const methodName = String(context.name);
function ReplacementMethod(this: any, ...args: any[]) {
logger.info(
import winston, { format } from "winston";
import DailyRotateFile from "winston-daily-rotate-file";
const winstonLogger = winston.createLogger({
format: winston.format.combine(
format.errors({ stack: true }),
format.timestamp({
format: "YYYY-MM-DD HH:mm:ss+ms",
}),
format.json()