Skip to content

Commit

Permalink
testing db conn
Browse files Browse the repository at this point in the history
  • Loading branch information
nourkrimesh committed Aug 10, 2023
1 parent 9b90864 commit 83d77dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 69,7 @@ app.all('*', (req: Request, res: Response, next: NextFunction) => {
app.use(errorHandlerMiddleware);

export const server = app.listen(config.server.port, () => {
console.log(`Server is running at http://localhost:${config.server.port}`);
console.log(`The Server is running at http://localhost:${config.server.port}`);
});

// handle rejections outside express eg: database errors etc..
Expand Down
16 changes: 9 additions & 7 deletions src/db/connection.ts
Original file line number Diff line number Diff line change
@@ -1,18 1,20 @@
import { config } from '../config/config';
import mongoose, { ConnectOptions } from 'mongoose';

let mongoURI;

if (config.environment === 'development') {
mongoURI = config.mongo.devDB.url;
} else if (config.environment === 'test') {
mongoURI = config.mongo.testDB.url;
}

const connectToDatabase = async () => {
let mongoURI;

if (config.environment === 'development') {
mongoURI = config.mongo.devDB.url;
} else if (config.environment === 'test') {
mongoURI = config.mongo.testDB.url;
}
console.log('1: trying to connect to database with connStr:', mongoURI);
if (mongoURI !== undefined) {
try {
console.log('trying to connect to database with connStr:', mongoURI);
console.log('2: trying to connect to database with connStr:', mongoURI);
await mongoose.connect(mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
Expand Down

0 comments on commit 83d77dd

Please sign in to comment.