-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
43 lines (30 loc) · 1.09 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
const express = require('express')
const mongoose = require('mongoose');
const hbs = require('express-handlebars');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
// Mongodb setup
mongoose.connect('mongodb://localhost:27017/ajaxCurd', {useNewUrlParser: true})
.then(()=> console.log('Mongo db connected'))
.catch((err)=> console.log(err))
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false}))
// parse application/json
app.use(bodyParser.json())
// view engine setup
app.engine( 'hbs', hbs( {
extname: 'hbs',
defaultLayout: 'main',
layoutsDir: __dirname + '/views/layouts/',
partialsDir: __dirname + '/views/partials/'
} ) );
app.set( 'view engine', 'hbs' );
// Set express static folder setup
app.use(express.static(path.join(__dirname, 'public')));
// Routers Setup
app.use('/', require('./routers/index'))
app.use('/users', require('./routers/users'))
// Port Setup
const PORT = process.env.PORT || 4000
app.listen(PORT, ()=> console.log(`server listening on port ${PORT}... `));