-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
30 lines (27 loc) · 862 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import express, { Express } from 'express';
import dotenv from 'dotenv';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import { route } from './routes';
const app: Express = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(route);
dotenv.config();
const connection = async (): Promise<void> => {
await mongoose
.connect(
`mongodb+srv://${process.env.USER_NAME}:${process.env.ACCESS_KEY}@catalogdb.rselcvp.mongodb.net/?retryWrites=true&w=majority`
)
.then(() => {
console.log(`MongoDB is connected to the application`);
})
.catch(() => {
console.log(`MongoDB connection failed`);
});
};
const port: number = 3000;
app.listen(port, () => {
connection();
console.log(`Application is running on port: ${port}`);
});