-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (47 loc) · 1.37 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
48
49
50
51
52
53
54
55
56
const dotenv = require("dotenv");
dotenv.config();
const express = require("express");
const mongoose = require("mongoose");
var path = require("path");
var cookieParser = require("cookie-parser");
const morgan = require("morgan");
const cors = require("cors");
const mongo2 = require("./dbSchema");
const golddata = require("./routes/Golddata");
const main = async () => {
try {
// Connecting to mongoDb Atlas
const conn = await mongoose.connect(process.env.MONGODB_URL);
await mongo2.connect();
const app = express();
var PORT = normalizePort(process.env.PORT);
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "jade");
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
app.use(express.json());
app.use(morgan("common"));
app.use(cors());
app.use("/all", golddata);
app.listen(PORT, () => {
console.log(`API is ready on http://localhost:${PORT}`);
});
await console.log(`conected to host : ${conn.connection.host}`);
} catch (error) {
console.log("error starting our application", error);
}
};
main();
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}