<commit_before>const config = require('config');
const express = require('express');
const lang = require('lang');
const metrics = require('./metrics');
const moment = require('moment');
const Database = require('./database');
const path = require('path');


config.addDefaultConfig(path.join(__dirname, 'config'));
lang.addDirectory(path.join(__dirname, 'lang'));
const app = express();
const db = new Database();
app.use(db.middleware());
setInterval(() => metrics.dispatch({cache: db.stats}), moment.duration(...config.cache.stats.interval).asMilliseconds());

require('./settings')(app);
metrics(app);
require('./security')(app);
require('./status')(app);
require('./headers')(app);
require('./auth')(app);
require('./content')(app);

// Server Startup
app.listen(config.backend.port);
console.log('listening on port', config.backend.port, 'with tier', config.tier);
<commit_msg>Fixed server crashing when metrics were disabled<commit_after>const config = require('config');
const express = require('express');
const lang = require('lang');
const metrics = require('./metrics');
const moment = require('moment');
const Database = require('./database');
const path = require('path');


// Set default server config
config.addDefaultConfig(path.join(__dirname, 'config'));
lang.addDirectory(path.join(__dirname, 'lang'));

const app = express();
const db = new Database();

app.use(db.middleware());
metrics.dispatch && setInterval(
    () => metrics.dispatch({cache: db.stats}),
    moment.duration(...config.cache.stats.interval).asMilliseconds()
);

require('./settings')(app);
metrics(app);
require('./security')(app);
require('./status')(app);
require('./headers')(app);
require('./auth')(app);
require('./content')(app);

// Server Startup
app.listen(config.backend.port);
console.log('listening on port', config.backend.port, 'with tier', config.tier);

{'fraction_non_alphanumeric': 0.20676691729323307, 'fraction_numerical': 0.0, 'mean_word_length': 6.481927710843373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1280920', 'n_tokens_mistral': 523, 'n_tokens_neox': 517, 'n_words': 119}