-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (26 loc) · 976 Bytes
/
server.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
// BASE SETUP
// =============================================================================
// call the packages we need
var express = require('express'); // call express
var cors = require('cors');
var router = express.Router();
var app = express(); // define our app using express
var bodyParser = require('body-parser');
app.use(cors())
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//try mongoose connect
var port = process.env.PORT || 8080; // set our port
const videosRouter = require('./routes/videos');
app.use('/videos', videosRouter);
/* Error handler middleware */
app.use((err, req, res, next) => {
console.log('punch');
const statusCode = err.statusCode || 500;
console.error(err.message, err.stack);
res.status(statusCode).json({ 'message': err.message });
return;
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
});