-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
31 lines (25 loc) · 905 Bytes
/
index.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
31
import express, { Express } from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import { foodRouter, programRouter, userRouter } from './routers/index';
import mongoose from 'mongoose';
import { logger } from './middlewares';
dotenv.config();
const PORT = process.env.PORT;
const app: Express = express();
app.use(express.json());
app.use(cors());
app.use(logger);
app.use('/food', foodRouter);
app.use('/user', userRouter);
app.use('/program', programRouter);
app.listen(PORT, () => {
console.log(`⚡️[server]: Server is running at http://127.0.0.1:${PORT}`);
mongoose.connect(`${process.env.MONGODB_SERVER_URL}`, {})
.then(() => {
console.info(`🤗 [server]: Connected to MongoDB`);
})
.catch((error: mongoose.Error) => {
console.error(`🤨 [server]: Failed to connect to mongodb\n ${error.message}`);
});
});