-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (34 loc) · 1.34 KB
/
server.js
File metadata and controls
43 lines (34 loc) · 1.34 KB
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
const express = require("express");
const mongoose = require("mongoose");
const config = require("config");
const path = require("path");
const app = express();
// Body parser Middleware
app.use(express.json());
// logger Middleware. --DEV mode.
app.use(require("./middleware/logger"));
// use routes.
app.use("/api/posts", require("./routes/api/posts"));
app.use("/api/users", require("./routes/api/users"));
app.use("/api/auth", require("./routes/api/auth"));
// DB config
var mongoURI="mongodb+srv://chnd_777:11223344@cluster0.dkjcuej.mongodb.net/myDB";
const { MongoClient, ServerApiVersion } = require('mongodb');
const uri = "mongodb+srv://chnd_777:11223344@cluster0.dkjcuej.mongodb.net/?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true, });
client.connect(err => {
const collection = client.db("myDB").collection("devices");
// perform actions on the collection object
client.close();
});
// Production step.
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html")); // relative path
});
}
// Port Variable
const PORT = process.env.PORT || 3000;
// listenting to server.
app.listen(PORT, () => console.log(`Server is started on PORT : ${PORT}`));