-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
29 lines (24 loc) · 890 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
const ENV = process.env.NODE_ENV || 'production'
require('dotenv').config({
path: `.env.${ENV}`
});
// External Module
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
// Local Module
const errorController = require("./controllers/errorController");
const exampleRouter = require("./routers/exampleRouter");
const MONGO_DB_URL =
`mongodb+srv://${process.env.MONGO_DB_USERNAME}:${process.env.MONGO_DB_PASSWORD}@kgcluster.ie6mb.mongodb.net/${process.env.MONGO_DB_DATABASE}`;
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.json());
app.use(exampleRouter);
app.use(errorController.get404);
const PORT = process.env.PORT || 3000;
mongoose.connect(MONGO_DB_URL).then(() => {
app.listen(PORT, () => {
console.log(`Server running at: http://localhost:${PORT}`);
});
});