-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (33 loc) · 995 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
/** @format */
require("dotenv").config();
console.log("MODE:", process.env.NODE_ENV);
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test")
require("dotenv").config();
require("./mongooseClient");
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const passport = require("passport");
//routes
const userRoutes = require("./routes/users");
var app = express();
//middleware
app.use(bodyParser.json());
app.use(cors());
app.use(passport.initialize());
app.use("/api/users", userRoutes);
//error
app.use((err, res) => {
if (err.name === "ValidationError") {
var valErrors = [];
Object.keys(err.errors).forEach((key) =>
valErrors.push(err.errors[key].message)
);
res.status(422).send(valErrors);
}
});
//dev port
//don't change
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => console.log(`Server started on port: ${PORT}`));
module.exports = app;