-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
30 lines (26 loc) · 874 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
const express = require("express");
const morgan = require("morgan");
const bodyparser = require("body-parser");
const mongoose = require("mongoose");
const secrets = require("./secrets/secrets");
mongoose.Promise = global.Promise;
mongoose.connect(
`mongodb+srv://${secrets.DATABASEUSERNAME}:${secrets.DATABASEPASSWORD}@shikhao-cluster.atqgg.mongodb.net/<dbname>?retryWrites=true&w=majority`,
{ useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true }
);
const app = express();
const users = require("./routes/users");
const port = process.env.PORT || 8000;
// Middelwares
//terminal outputs
app.use(morgan("dev"));
//parse as json
app.use(bodyparser.json());
//Routes
app.use("/users", users);
app.get("/", (req, res) => {
res.send("Hi there");
});
app.listen(port, () => {
console.log(`Server is running at port http://localhost:${port}`);
});