-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
63 lines (40 loc) · 1.12 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
57
58
59
60
61
//node modules
const express=require("express");
const path=require("path");
const bodyParser=require("body-parser");
//routers
const loginrouter=require("./routes/login");
const adminrouter=require("./routes/admin");
const apirouter=require("./api/api");
const storedetailsrouter=require("./routes/storedetails")
const dbConnect=require("./dbconnect");
const app=new express()
//middleware's
app.use(express.json());
app.use(bodyParser.urlencoded({extended:true}));
// setting value
app.set("view engine" ,"ejs");
app.set("views","./views");
let port=process.env.PORT || 3000;
//connecting to db
async function d() {
await dbConnect();
}
d();
//routing
app.use("/public",express.static(path.join(__dirname+"/public")));
app.use("/api",apirouter);
app.use("/login",loginrouter);
app.use("/admin",adminrouter);
app.use("/token",storedetailsrouter);
app.get("/",(req,res)=>{
res.sendFile(path.join(__dirname+"/public/index.html"));
})
//404 page
app.get("/*",(req,res)=>{
res.send("<h1>404 Not Found</h1>");
})
process.on("uncaughtException",()=>{
//close the db
})
app.listen(port,()=>{console.log("server started")});