Skip to content

Instantly share code, notes, and snippets.

@antoniusostermann
antoniusostermann / configuration_object_example.ts
Created January 24, 2018 14:38
An example of how to do configuration with typescript objects. Module developers have the possbility to define default values (which means they are optional for module users) and required values while module clients get only one simple interface to fulfill.
/** Users of your module possibly never need interfaces in this namespace. But you will. */
export namespace Configuration {
/** Configuration defaults -> all of these keys are optional for users of your module. */
export interface Defaults {
/** If set to true, my module will always fail. Default = false */
alwaysFail: boolean;
}
/** Required configuration options, no defaults are used here */
@vlucas
vlucas / encryption.js
Last active July 23, 2024 01:24
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);