-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (42 loc) · 1.14 KB
/
server.js
File metadata and controls
43 lines (42 loc) · 1.14 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
//imports
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const MongoClient = require("mongodb").MongoClient;
const cors = require("cors");
const userrouter = require("./routes/userrouter");
const users = require("./models/userschema");
const morgan = require("morgan");
const path = require("path");
require("dotenv/config");
//middleware
app.use(cors());
app.use(morgan("dev"));
//body-parser
app.use(express.json());
//router-config
app.use("/users", userrouter);
//router
//server
const port = process.env.PORT || 5002;
app.listen(port, () => {
console.log("http://localhost:" + port);
});
//production
app.use(express.static(path.join(__dirname, "client/build")));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
//db-connnection
mongoose.set("useNewUrlParser", true);
mongoose.set("useUnifiedTopology", true);
mongoose.connect(
"mongodb+srv://dharwin:9715928749@dharwin.wkbz4.mongodb.net/user-managment-system?retryWrites=true&w=majority",
(err) => {
if (err) {
throw err;
console.log(err);
}
console.log("DB connected");
}
);