Constructor
new NotesServer() → {NotesServer}
Create a new NotesServer instance
- Source:
Returns:
New NotesServer instance
- Type
- NotesServer
Example
const server = new NotesServer();
await server.initializeApp();
server.startServer();
Classes
Members
app :express.Application
Express application instance
Type:
- express.Application
- Source:
Methods
createNoteRepository() → {CouchDbNoteRepository|MongoDbNoteRepository}
Create the appropriate repository based on the DB_VENDOR environment variable. Supports both CouchDB and MongoDB implementations.
- Source:
Throws:
-
When an unsupported database vendor is specified
- Type
- Error
Returns:
The configured repository instance
Example
// With DB_VENDOR='mongodb'
const repo = server.createNoteRepository(); // Returns MongoDbNoteRepository
// With DB_VENDOR='couchdb' (default)
const repo = server.createNoteRepository(); // Returns CouchDbNoteRepository
gracefulShutdown(timeoutopt) → {void}
Graceful shutdown function that handles cleanup and ensures all connections are closed properly. Implements a timeout mechanism to force shutdown if graceful shutdown takes too long.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
timeout |
number |
<optional> |
10000 | Timeout in milliseconds before forcing shutdown |
- Source:
Returns:
- Type
- void
Example
// Manual shutdown
server.gracefulShutdown();
// With custom timeout
server.gracefulShutdown(5000); // 5 second timeout
(async) initializeApp(noteRepositoryopt, nullable) → {Promise.<{app: express.Application, repository: NoteRepository}>}
Initialize the Express application with middleware, routes, and error handling. Sets up the complete application stack including security, CORS, static files, and API routes.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
noteRepository |
NoteRepository |
<optional> <nullable> |
null | Optional repository instance for dependency injection (useful for testing) |
- Source:
Throws:
-
When repository initialization fails
- Type
- Error
Returns:
Initialized app and repository
- Type
- Promise.<{app: express.Application, repository: NoteRepository}>
Example
// Default initialization
const { app, repository } = await server.initializeApp();
// With custom repository (for testing)
const mockRepo = new MockNoteRepository();
const { app, repository } = await server.initializeApp(mockRepo);
startServer() → {http.Server}
Start the HTTP server and set up signal handlers for graceful shutdown. The server will listen on the configured HOST and PORT.
- Source:
Throws:
-
When server fails to start
- Type
- Error
Returns:
The started HTTP server instance
- Type
- http.Server
Example
const server = new NotesServer();
await server.initializeApp();
const httpServer = server.startServer();
console.log('Server started successfully');