-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (28 loc) · 1007 Bytes
/
Copy pathserver.js
File metadata and controls
30 lines (28 loc) · 1007 Bytes
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
const express = require('express');
const app = express();
const path = require('path');
require('dotenv').config();
const mainRoute = require('./routes/index');
const errorHandler = require('./middleware/errorHandler');
const port = process.env.PORT
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
app.use(bodyParser.json())
app.use(express.static('public'));
app.use(express.static('views'));
app.use(express.static('scripts'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(mainRoute);
app.use(errorHandler);
const url = process.env.MONGOURL;
mongoose.connect(url ,{
// useNewUrlParser : true,
useUnifiedtopoLogy : true})
var db= mongoose.connection;
db.on('error',()=>{console.log("Error in connecting to database.");})
db.once('open',()=>{console.log("Database Connected");})
app.set('view engine','ejs');
console.log(app.get('views'));
app.listen(port,()=>{
console.log(`server run http://localhost:${port}`);
});