-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
52 lines (35 loc) · 1.31 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require("dotenv").config();
const express = require("express");
const app = express();
const mongoose = require("mongoose");
require("./db/conn");
const cookieParser = require("cookie-parser");
const Products = require ("./models/productsSchema");
const DefaultData = require ("./defaultdata");
const cors=require("cors");
const router=require("./routes/router");
app.use(express.json());
app.use(cookieParser(""));
app.use(cors());
//for using router api we use, use methode..
// app.use("/db",router);
app.use(router);
const port = process.env.PORT || 8005;
//////////////////////////////////Deployment///////////////////////////////////////////
//for deploying our react app ...it allow when we in production environment,
//then run an express middleware that gives the server access to our react app.
//by which our react app deployed as html file.
//ak tarah se backend ko frontend se jodne ke liye in production environment..use ho rha hai
if (process.env.NODE_ENV === "production") {
app.use(express.static("frontend/build"))
}
else {
app.get("/", (req, res) => {
res.send("API is running..");
});
}
////////////////////////////Deployment over////////////////////////////////////////////////
app.listen(port,()=>{
console.log(`server is running on port number ${port}`);
})
DefaultData();