-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (38 loc) · 1.26 KB
/
Copy pathapp.js
File metadata and controls
49 lines (38 loc) · 1.26 KB
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
var express = require('express')
, app = express()
, bodyParser = require('body-parser')
, mongoose = require('mongoose')
, jwt = require('jwt-simple')
, moment = require('moment-timezone')
// config hora e timezone
moment().tz("America/Recife").format();
// conexao com MlAB
mongoose.Promise = require('bluebird');
mongoose.connect('mongodb://admin:admin@ds113660.mlab.com:13660/onheredb');
// CONNECTION EVENTS
// When successfully connected
mongoose.connection.on('connected', function () {
console.log('Mongoose default connection openned ');
});
// If the connection throws an error
mongoose.connection.on('error',function (err) {
console.log('Mongoose default connection error: ' + err);
});
// When the connection is disconnected
mongoose.connection.on('disconnected', function () {
console.log('Mongoose default connection disconnected');
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
var port = process.env.PORT || 8080;
var rotas = require('./rotas');
app.use('/api', rotas);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
res.json({
status: '404',
message: 'Not Found, hihihi',
});
});
app.listen(port);
console.log('conectado a porta ' + port);