-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (26 loc) · 1 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
const express = require('express');
const app = express();
const http = require('http');
const path = require('path');
const cors = require('cors');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/monES', {useNewUrlParser: true});
mongoose.set('useCreateIndex', true);
// for serving express static files
app.use(express.static(path.join(__dirname, 'public'), {dotfiles: 'allow'}));
app.use(bodyParser.urlencoded({
extended: true
}));// for parsing application/x-www-form-urlencoded
app.use(bodyParser.json());// for parsing application/json
//cross domain
app.use(cors());
// routes =======================================================================
const routes = require('./routes');
app.use('/api', routes);
// listen (start app with node index.js) ======================================
// Starting server
const httpServer = http.createServer(app);
httpServer.listen(6565);
console.log("Server on port: " + 6565);
module.exports = app;