'use strict';
var fs = require('fs');
var express = require('express');
var pg = require('pg');
var busboy = require('connect-busboy');
var app = express();
app.use(busboy());

var env = process.env.NODE_ENV || 'development';
 // Setup view engine for server side templating
app.engine('.html', require('ejs').__express);
app.set('view engine', 'html');
// Setup path where all server templates will reside
app.set('views', 'server/templates');

if (env === 'development') {
  app.use(express.static('dist/client/'));
} else {
  app.use(express.static('client/'));
}

require('./server/routes/routes')(app);

//Creates database client and connect it to the database.
//If our table doesn't exist then it is created.
var dbClient = new pg.Client(process.env.DATABASE_URL);
dbClient.connect(function(err, client) {
  if (err) {
    console.log(err);
  }
  client.query('CREATE TABLE IF NOT EXISTS Files(id SERIAL PRIMARY KEY, filename VARCHAR(64) NOT NULL, filesize INT NOT NULL, data BYTEA NOT NULL, created TIMESTAMP DEFAULT current_timestamp NOT NULL)');
  // fs.readFile('client/assets/play/karttatausta.png', 'hex', function(err, imgData) {
  //   imgData = '\\x' + imgData;

  //   //remove the line below
  //   var stats = fs.statSync('client/assets/play/karttatausta.png');
  //   var fileSize = stats.size;
  //   console.log(fileSize);
  //   var query = 'INSERT INTO Files(filename, filesize, data) VALUES (\'karttatausta.png\', ' + fileSize + ', ' + imgData + ')';
  //   console.log(query);
  //   client.query('INSERT INTO Files(filename, filesize, data) VALUES ($1, $2, $3)', ['karttatausta.png',fileSize, imgData], function(err, writeResult) {
  //         console.log('err', err, 'pg writeResult', writeResult);
  //       });
  // });
});

// pg.connect(process.env.DATABASE_URL, function(err, client) {
//   if (err) {
//     console.log(err);
//   }
  // var query = client.query('SELECT * FROM testi');

  // query.on('row', function(row) {
  //   console.log(JSON.stringify(row));
  // });
// });

app.use(express.static('client/'));
// app.use('/', routes);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function(err, req, res) {
    res.status(err.status || 500);
    res.render('error', {
      status: err.status,
      message: err.message,
      error: err
    });
  });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});
var portNumber = process.env.PORT || 3000;
var server = app.listen(portNumber, function() {

  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});

@@ -11,32 +11,8 @@
 t';%0A
-var fs = require('fs');%0A
 var 
@@ -195,16 +195,80 @@
 pment';%0A
+%0A//Static files for client%0Aapp.use(express.static('client/'));%0A%0A
  // Setu
@@ -387,16 +387,17 @@
 html');%0A
+%0A
 // Setup
@@ -1094,1029 +1094,9 @@
 ');%0A
-  // fs.readFile('client/assets/play/karttatausta.png', 'hex', function(err, imgData) %7B%0A  //   imgData = '%5C%5Cx' + imgData;%0A%0A  //   //remove the line below%0A  //   var stats = fs.statSync('client/assets/play/karttatausta.png');%0A  //   var fileSize = stats.size;%0A  //   console.log(fileSize);%0A  //   var query = 'INSERT INTO Files(filename, filesize, data) VALUES (%5C'karttatausta.png%5C', ' + fileSize + ', ' + imgData + ')';%0A  //   console.log(query);%0A  //   client.query('INSERT INTO Files(filename, filesize, data) VALUES ($1, $2, $3)', %5B'karttatausta.png',fileSize, imgData%5D, function(err, writeResult) %7B%0A  //         console.log('err', err, 'pg writeResult', writeResult);%0A  //       %7D);%0A  // %7D);%0A%7D);%0A%0A// pg.connect(process.env.DATABASE_URL, function(err, client) %7B%0A//   if (err) %7B%0A//     console.log(err);%0A//   %7D%0A  // var query = client.query('SELECT * FROM testi');%0A%0A  // query.on('row', function(row) %7B%0A  //   console.log(JSON.stringify(row));%0A  // %7D);%0A// %7D);%0A%0Aapp.use(express.static('client/'));%0A// app.use('/', routes
+%7D
 );%0A%0A
@@ -1746,16 +1746,17 @@
 %7D);%0A%7D);%0A
+%0A
 var port

Clean server.js