-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (35 loc) · 1.23 KB
/
server.js
File metadata and controls
41 lines (35 loc) · 1.23 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
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
var passport = require('passport');
var morgan = require('morgan');
var config = require('./_config');
var appmetrics = require('appmetrics');
var chalk = require('chalk');
var port = process.env.PORT || 3000;
var app = express();
app.use(passport.initialize());
app.use(cors());
app.use(morgan('dev'));
app.set('key', config.secret);
app.use(require('./controllers'));
var monitoring = appmetrics.monitor();
monitoring.on('initialized', function (env) {
console.log(chalk.yellow('[appmetric] init'));
});
monitoring.on('http', function (data) {
console.log(chalk.yellow('[appmetric] duration='+data.duration+' ms url='+data.url));
});
monitoring.on('mongo', function (data) {
console.log(chalk.yellow('[appmetric] duration='+data.duration+' ms query='+JSON.stringify(data.query)));
});
monitoring.on('cpu', function (cpu) {
console.log('[' + new Date(cpu.time) + '] CPU: ' + cpu.process);
});
monitoring.on('request', function (data) {
console.log(chalk.yellow('[appmetric] duration='+data.duration+' ms url='+data.request));
});
app.listen(port, () => {
console.log('Application using port %d', port);
});
module.exports = app;