This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const OK = 200; | |
export const CREATED = 201; | |
export const BAD_REQUEST = 400; | |
export const UNAUTHORIZED = 401; | |
export const FORBIDDEN = 403; | |
export const NOT_FOUND = 404; | |
export const CONFLICT = 409; | |
export const UNPROCESSABLE_CONTENT = 422; | |
export const TOO_MANY_REQUESTS = 429; | |
export const INTERNAL_SERVER_ERROR = 500; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: | |
* create a .env file containing the correct env names | |
* export const PORT = getEnv("PORT"); | |
* const DB_URL = getEnv("DATABASE_URL"); // throws if not defined | |
*/ | |
const getEnv = (key: string, defaultValue?: string): string => { | |
const value = process.env[key] || defaultValue; | |
if (value === undefined) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bcrypt from "bcryptjs"; | |
export const hashValue = async (value: string, saltRounds?: number) => | |
bcrypt.hash(value, saltRounds || 12); | |
export const compareValue = async (value: string, hashedValue: string) => | |
bcrypt.compare(value, hashedValue).catch(() => false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: | |
* import { logger } from './logger'; | |
* logger.info("Server started"); | |
* logger.error("Something went wrong"); | |
*/ | |
import { createLogger, format, transports } from "winston"; | |
import "winston-daily-rotate-file"; | |
import path from "path"; |