-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
47 lines (39 loc) · 1.26 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require("express");
const path = require("path");
const mongoose = require("mongoose");
const cors = require("cors");
require("dotenv").config();
const app = express();
// Middlewares
app.use(cors());
app.use(express.json());
// Mongoose to MongoDB
const uri = process.env.MONGODB_URI;
mongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
const db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", function () {
console.log("Connected to remote database (MongoDB)");
});
// Variables
const port = process.env.PORT || 3000;
// Routes
const notesRoutes = require("./routes/notes");
app.use("/api", notesRoutes);
// For deployment
app.use(express.static(path.join(__dirname, "build")));
app.get("/*", (req, res) => {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
app.listen(port, () => {
console.log("\n-----------NOTE-TAKING WEB APP-----------");
console.log(" CSE Sem-3 Web Technologies Project\n");
console.log(":) Sarthak S Kumar\n:) Satyam Kumar\n:) Sathish Kumar G");
console.log("-----------------------------------------");
console.log("Express server running on port 5000 (Local Deployment PORT)");
});
module.exports = app;