-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (25 loc) · 880 Bytes
/
server.js
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
const path = require('path');
const result = require('dotenv').config({
path: path.join(__dirname, `./.env.${process.env.NODE_ENV}`),
});
if (result.error) {
throw new Error(result.error);
}
const express = require('express');
const cors = require('cors');
const { postgrator } = require('./lib/db');
const app = express();
app.use(express.json());
app.use(cors());
app.use('/users', require('./routes/users'));
app.use('/pets', require('./routes/pets'));
app.use('/statuses', require('./routes/statuses'));
app.use('/hearties', require('./routes/hearties'));
const HOST = process.env.HOST;
const PORT = +process.env.PORT;
postgrator.migrate().then((result) => {
console.log(`migrated db successfully:`, result)
app.listen(PORT, HOST, () => {
console.log(`server is listening at http://${HOST}:${PORT}`);
});
}).catch(err => console.error(err));