-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (34 loc) · 967 Bytes
/
app.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
32
33
34
35
36
37
38
39
40
41
42
43
44
require('dotenv').config();
const cors = require('cors');
// express
const express = require('express');
const app = express();
// database
const connectDB = require('./db/connect');
// routers
const effectsRouter = require('./routes/effects');
const tagsRouter = require('./routes/tags');
const brandsRouter = require('./routes/brands');
const notFound = require('./errors/notFound');
const errorHandler = require('./middleware/errorHandler');
//middlewares
app.use(express.json());
app.use(cors());
//app.use(express.static('public'));
app.use('/api/v1/effects', effectsRouter);
app.use('/api/v1/tags', tagsRouter);
app.use('/api/v1/brands', brandsRouter);
app.use(notFound);
app.use(errorHandler);
const start = async () => {
try {
await connectDB(process.env.MONGO_URI);
app.listen(
process.env.PORT,
console.log(`Server is listening on port ${process.env.PORT}`)
);
} catch (error) {
console.log(error);
}
};
start();