-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (33 loc) · 984 Bytes
/
app.js
File metadata and controls
41 lines (33 loc) · 984 Bytes
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
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
// * IMPORT ENV FILE
require("dotenv/config");
// * EXPRESS CONFIGURATIONS
const app = express();
app.use(express.json());
app.use(bodyParser.json());
// * IMPORT APPICATION ROUTES
const userRoutes = require("./routes/users");
// * USE APPLICATION ROUTES
app.use("/users", userRoutes);
// * INDEX ROUTE
app.get("/", (req, res) => {
res.send("This app is made by tyb9900");
});
// * DATABASE CONNECTION
mongoose.connect(process.env.DB_CONNECTION, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
// ! DATABASE CONNECTION * SUCCCESS OR ERROR
const db = mongoose.connection;
db.on("error", console.log.bind(console, "Unable to connect to database"));
db.once(
"open",
console.log.bind(console, "Successfully cconnected to database")
);
// * LISTEN TO PORT
app.listen(process.env.PORT || 3000, () => {
console.log(`Server started on port`);
});