Skip to content

Instantly share code, notes, and snippets.

@andresgcarmona
Created March 20, 2023 13:08
Show Gist options
  • Save andresgcarmona/9fc7177dbf5a18220fc2a7aaf5ae2cba to your computer and use it in GitHub Desktop.
Save andresgcarmona/9fc7177dbf5a18220fc2a7aaf5ae2cba to your computer and use it in GitHub Desktop.
Singleton Typescript
export class Singleton {
// Define your props here
private _express: Application = express();
private static _instance: Singleton;
constructor() {
if (Singleton._instance) {
return Singleton._instance;
}
// You don't have an instance, so continue
// Remember, to set the _instance property
Singleton._instance = this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment