-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (29 loc) · 915 Bytes
/
index.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
53
54
const http = require('http');
const express = require('express');
const mongoose = require('mongoose');
const env = require('dotenv');
const { createConnection } = require('./models/db');
const orderRoute = require('./routes/order');
const app = express();
const server = http.createServer(app);
//middlewares
app.use(express.urlencoded({extended: true}));
app.use(express.json());
app.use(express.static('public'));
//app configuration
app.set('views','views');
app.set('view engine', 'ejs');
env.config();
//routes
app.use('/', orderRoute);
//createConnection
createConnection();
const db = mongoose.connection;
//db listener
db.on('error', error => console.log(error))
db.once('open', () => console.log('connection established to database'));
const PORT = 3000 || process.env.PORT;
// server listener
server.listen(3000, ()=> {
console.log(`the server is listening on ${PORT}`);
})