<commit_before>var fs = require("fs"),
    less = require("less"),
    http = require("http"),
    express = require("express"),
    socketio = require("socket.io");

console.log("Generating app...");

var app = express();
app.use(express.static(__dirname + "/public"));

var server = http.createServer(app);

var db = {};

db.buildings = [
    {
        name: "Toothpaste Factory",
        votes: 6,
        id: 0
    },
    {
        name: "Shopping Mall",
        votes: 0,
        id: 1
    },
    {
        name: "Police Station",
        votes: -2,
        id: 2
    }
];

var dbFile = "db.json";

console.log("Loading database from " + dbFile + "...");

if(fs.existsSync(dbFile) === true) {
    var json = fs.readFileSync(dbFile);

    if(json) {
        var data = JSON.parse(json);

        if(data) {
            db = data;
        } else {
            console.log("Failed to parse " + dbFile + ".");
        }
    } else {
        console.log("Failed to read " + dbFile + ".");
    }
}

var io = socketio(server);

require("./sockets.js")(io, db);

setInterval(function() {

    fs.writeFile(dbFile, JSON.stringify(db), function(err) {
        if(err) {
            console.log("Failed saving database to file: " + err);
        }
    });

}, 30 * 1000); /* save the database to a json file, every 30 seconds */

/* Start the server */

console.log("Starting server...");
server.listen(8080);<commit_msg>server now ends post-startup with the --test flag<commit_after>var fs = require("fs"),
    less = require("less"),
    http = require("http"),
    express = require("express"),
    socketio = require("socket.io");

console.log("Generating app...");

var app = express();
app.use(express.static(__dirname + "/public"));

var server = http.createServer(app);

var db = {};

db.buildings = [
    {
        name: "Toothpaste Factory",
        votes: 6,
        id: 0
    },
    {
        name: "Shopping Mall",
        votes: 0,
        id: 1
    },
    {
        name: "Police Station",
        votes: -2,
        id: 2
    }
];

var dbFile = "db.json";

console.log("Loading database from " + dbFile + "...");

if(fs.existsSync(dbFile) === true) {
    var json = fs.readFileSync(dbFile);

    if(json) {
        var data = JSON.parse(json);

        if(data) {
            db = data;
        } else {
            console.log("Failed to parse " + dbFile + ".");
        }
    } else {
        console.log("Failed to read " + dbFile + ".");
    }
}

var io = socketio(server);

require("./sockets.js")(io, db);

setInterval(function() {

    fs.writeFile(dbFile, JSON.stringify(db), function(err) {
        if(err) {
            console.log("Failed saving database to file: " + err);
        }
    });

}, 30 * 1000); /* save the database to a json file, every 30 seconds */

/* Start the server */

console.log("Starting server...");
server.listen(8080);

if(process.argv[2] == "--test") {
    console.log("Test ran successfully.");
    process.exit();
}
{'fraction_non_alphanumeric': 0.17565745111260958, 'fraction_numerical': 0.012474713418745786, 'mean_word_length': 2.1732620320855616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1288966', 'n_tokens_mistral': 999, 'n_tokens_neox': 960, 'n_words': 228}