-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (43 loc) · 1.6 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// require('dotenv').config();
// import path from "path";
// const path = require("path");
const { fileURLToPath } = require("url");
// import { fileURLToPath } from "url";
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const morgan = require("morgan");
const path = require("path");
var bodyParser = require("body-parser");
// const __file_name = fileURLToPath(import.meta.url);
// const __dirname = path.dirname(__file_name);
// const path = require('path');
const currentFilePath = __filename;
const currentDirPath = path.dirname(__filename);
console.log(currentDirPath);
const port = process.env.PORT || 3010;
const app = express();
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.json());
mongoose.connect(
process.env.MONGOLAB_URI ||
"mongodb+srv://admin_aravind:battlebee4799@cluster0.5xhau.mongodb.net/NotesDB",
{ useNewUrlParser: true, useUnifiedTopology: true }
);
// to verify connection with mongodb cloud
mongoose.connection.once("open", () => console.log("connected"));
const users = require("./routes/users");
//a http request logger.
//a http request logger
app.use(morgan("tiny"));
//whenever we go into path localhost:3000/users then code in routes/users.js will be
//executed
app.use("/", users);
// if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(currentDirPath, "/client/build")));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
// }
app.listen(port, () => console.log("server up and running at port " + port));