Express TS project
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

1234567891011121314151617181920212223242526272829
  1. import { MongoClient, Collection } from 'mongodb';
  2. // You can define any db name you are looking for here
  3. export const DB_NAME = 'anamnesis';
  4. const DATABASE_URL = 'mongodb://localhost:27017/' + DB_NAME;
  5. let databaseClient: MongoClient;
  6. export function connectToDatabaseServer() {
  7. return new Promise<void>((resolve, reject) => {
  8. const defaultMongoClient = new MongoClient(DATABASE_URL);
  9. defaultMongoClient.connect(async (error, returnedDatabaseClient) => {
  10. if (error) {
  11. reject(error);
  12. return;
  13. }
  14. databaseClient = returnedDatabaseClient;
  15. resolve();
  16. });
  17. })
  18. }
  19. export function getDatabaseClient() {
  20. return databaseClient;
  21. }