-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (29 loc) · 1.23 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
const express= require("express");
const exphbs = require("express-handlebars");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const methodOverride = require('method-override');
require("dotenv").config({path:'./config/keys.env'});
const productRoutes = require("./routes/product");
const generalRoutes = require("./routes/general");
const app = express();
app.use(bodyParser.urlencoded({extended:false}));
app.use(methodOverride('_method'));
app.use(express.static("public"));
app.use("/",generalRoutes);
app.use("/product",productRoutes);
app.engine("handlebars",exphbs());
app.set("view engine","handlebars");
const MONGO_DB_URL=`mongodb+srv://${process.env.MONGO_DB_USERNAME}:${process.env.MONGO_DB_PASSWORD}@test1-91w38.mongodb.net/${process.env.MONGO_DB_DATABASE_NAME}?retryWrites=true&w=majority`;
mongoose.set('useCreateIndex', true);
mongoose.connect(MONGO_DB_URL, {useNewUrlParser: true,useUnifiedTopology: true })
.then(()=>{
console.log(`You have successfully connected to your mongoDB database`);
})
.catch((err)=>{
console.log(`Sorry, something occured :${err}`);
});
const port = process.env.PORT || 3000;
app.listen(port,()=>{
console.log(`Your Web Server has been connected`);
});