-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (25 loc) · 796 Bytes
/
index.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
const express = require("express");
const mongoose = require("mongoose");
require("dotenv").config({ path: ".env" });
const userRouter = require("./routes/userRoutes");
const AppError = require("./utils/error");
const errorHandler = require("./middleware/errorHandler");
const app = express();
mongoose
.connect("mongodb://127.0.0.1:27017/nodeauth", {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("> DB connection successful ... ");
});
app.use(express.json());
app.use("/api/users", userRouter);
app.all("*", (req, res, next) => {
next(new AppError(`can't find ${req.originalUrl} on this server`, 404));
});
app.use(errorHandler);
const PORT = 8080;
app.listen(PORT, () => {
console.log(`> App running on port ${PORT} ...`);
});