-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
32 lines (24 loc) · 797 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
31
32
require('dotenv').config();
import express from 'express';
import morgan from 'morgan';
import healthRouter from './api/meta';
import helloRouter from './api/hello';
import mongoose from 'mongoose';
const app = express();
const PORT = process.env.PORT || 3000;
const MONGO_URL = process.env.MONGO_URL || 'mongodb://localhost:27017/hello-api';
mongoose.connect(MONGO_URL, () => {
console.log('connected to DB');
});
// parsing middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// disable morgan logs during test
if (process.env.NODE_ENV !== 'test') app.use(morgan('combined'));
// Main Routes
app.use('/_meta', healthRouter);
app.use('/hello', helloRouter);
app.listen(PORT, () => {
console.log(`API started on port ${PORT}`);
});
export default app;