-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (31 loc) · 1.18 KB
/
server.js
File metadata and controls
37 lines (31 loc) · 1.18 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
import express from 'express';
import connection from './db.js';
import Router from './route.js';
import cors from 'cors';
import bodyParser from "body-parser";
import dotenv from 'dotenv';
//import path from 'path'
dotenv.config();
const app=express();
//app.use(express.json());
app.use(cors());
app.use(bodyParser.json({extended:true}))
app.use(bodyParser.urlencoded({extended:true}));
// if(process.env.NODE_ENV==='production'){ //this is will execute on heroku only
// app.use(express.static("client/build"));
// }
//or productoin--->
app.use(express.static( "./client/build"));
app.get("/",(req,res)=>{
res.sendFile("./client/build/index.html")
})
app.use('/',Router);
const PORT=process.env.PORT || 8000;
app.listen(PORT, ()=>{console.log(`server is running on port ${PORT}`)})
const username=process.env.DB_USERNAME;
const password=process.env.db_password;
const DB=process.env.MONGODB_URI ||`mongodb+srv://${username}:${password}@cluster0.i4nhnfk.mongodb.net/VIDEO?retryWrites=true&w=majority`;
connection(DB);
// const bodyParser = require('body-parser');
// app.use(bodyParser.json());
// app.use(bodyParser.urlencoded({ extended: false }))