-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (30 loc) · 907 Bytes
/
index.js
File metadata and controls
37 lines (30 loc) · 907 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
31
32
33
34
35
36
37
const express = require('express');
const app = express();
const path = require('path');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const logger = require('express-log');
// config
const port = 3000;
// set up middleware
app.use(logger());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// set up connection
mongoose.connect('mongodb://localhost/cms');
mongoose.set('debug', true);
let db = mongoose.connection;
// database events
db.on('error', console.error.bind(console, 'Mongoose:'));
db.once('open', () => {
console.log('Connected to mongoose');
});
// public (static) route
app.use('/', express.static(path.join(__dirname, 'public')));
// API connection
const apiRouter = require('./api/api-router')();
app.use('/api', apiRouter);
// starting the app
app.listen(port, () => {
console.log('listening on *:' + port);
});