← Back to design patterns mapcreational
🔒
Design Pattern
Singleton
Ensure only one shared instance exists for a resource.
Visual Diagram
getInstance() -> exists? return same -> missing? create once
When To Use
- ->DB connection pool shared across the app
- ->Config loaded once at startup
- ->Logger with one output stream
- ->Shared in-memory cache
Used in: Mongoose connection, Winston logger, config manager
singleton.js
Live Editor
Loading...
Output
Run code to see output...
Related Blog
Open the Singleton blog and use the contextual back link to return here after reading.
Open Singleton Blog →