-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (28 loc) · 1.05 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
const express= require("express");
const errorhandler = require("./middleware/errorhandler");
const app=express();
const dotenv= require("dotenv").config();
const connectdb=require("./config/dbconnect")
const cookieParser = require("cookie-parser");
const path = require("path")
app.use(express.static(path.join(__dirname,"public")));
app.use(express.urlencoded({extended: true}));
app.set("view engine","ejs");
app.use(cookieParser());
connectdb();
const port=process.env.PORT || 5000;
app.get("/",(req,res)=>{
res.sendFile(path.join(__dirname,"./views/homepage.html"));
})
//built in middleware for accepting the json input form
//post method
app.use(express.json());
// custom middleware for converting the error to json
app.use(errorhandler)
app.use("/contact",require("./routes/contactroutes"));
app.use("/user",require("./routes/user"));
// middleware should be use properly the route here is contact means we need to
// write localhost:5001/contact/routewhichismentionedinthecontactroutes
app.listen(port,()=>{
console.log("server is running");
})