-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
40 lines (34 loc) · 999 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
require("dotenv").config();
const express = require("express");
const mongoose = require('mongoose');
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const authRoutes = require("./routes/auth");
const tinyUrlRoutes = require("./routes/tinyurl");
// Boot
const app = express();
app.set('port', process.env.PORT || 4000);
// Database
mongoose.connect(process.env.DATABASE, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
}).then(() => {
console.log("bravo database connected ........")
})
// App config
app.use(bodyParser.json());
app.use(cookieParser());
app.use(cors());
// Auth Routes
app.use("/api", authRoutes);
app.use("/api/tinyurl", tinyUrlRoutes);
app.use((req, res) => {
return res.status(404).json({ error: "Not Found" })
});
// Start server
const port = process.env.PORT || 4000;
const server = app.listen(port, () => {
console.log("running server...", port);
});