var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
///lets require/import the mongodb native drivers.
var mongodb = require('mongodb');

//We need to work with "MongoClient" interface in order to connect to a mongodb server.
var MongoClient = mongodb.MongoClient;

// Connection URL. This is where your mongodb server is running. ANPASSEN
var url = 'mongodb://localhost:27017/local';


app.use(express.static(__dirname + '/public'));

//Deliver index.html with client javascript code
app.get('/', function (req, res) {
    res.sendFile(__dirname + '/index.html');
});


function mongodb_schreiben(chatentry) {
    collection.insert(chatentry, function (err, result) {
        if (err) {
            console.log(err);
        } else {
            console.log('Inserted into the chat collection. The documents inserted with "_id" are:', result);
        }
    });
}

//Create server socket for client connection
io.on('connection', function (socket) {
    console.log('a user connected');

    socket.on('chat message', function (msg) {
        io.emit('chat messages', msg);
        msg = "{'Message':'" + msg + "'}";
        console.log('message: ' + msg);
        //mongodb_schreiben(msg);
    })

    //socket.on('disconnect', function(){  //Create disconnect, if client refreshes/exits index.html
    //    console.log('user disconnect');
    //});
});
var port = process.env.PORT || '3000';
http.listen(port, function () {
    console.log('listening on port ' + port);

    /*    MongoClient.connect(url, function (err, db) {
     if (err) {
     console.log('Unable to connect to the mongoDB server. Error:', err);
     }
     else {
     var collection = db.collection('chathistory');
     }
     });*/
});
@@ -129,820 +129,190 @@
 p);%0A
-///lets require/import the mongodb native drivers.%0Avar mongodb = require('mongodb');%0A%0A//We need to work with %22MongoClient%22 interface in order to connect to a mongodb server.%0Avar MongoClient = mongodb.MongoClient;%0A%0A// Connection URL. This is where your mongodb server is running. ANPASSEN%0Avar url = 'mongodb://localhost:27017/local';%0A%0A%0Aapp.use(express.static(__dirname + '/public'));%0A%0A//Deliver index.html with client javascript code%0Aapp.get('/', function (req, res) %7B%0A    res.sendFile(__dirname + '/index.html');%0A%7D);%0A%0A%0Afunction mongodb_schreiben(chatentry) %7B%0A    collection.insert(chatentry, function (err, result) %7B%0A        if (err) %7B%0A            console.log(err);%0A        %7D else %7B%0A            console.log('Inserted into the chat collection. The documents inserted with %22_id%22 are:', result);%0A        %7D%0A    %7D);%0A%7D
+%0Aapp.use(express.static(__dirname + '/public'));%0A%0A//Deliver index.html with client javascript code%0Aapp.get('/', function (req, res) %7B%0A    res.sendFile(__dirname + '/index.html');%0A%7D);
 %0A%0A//
@@ -609,203 +609,16 @@
     
-    //mongodb_schreiben(msg);%0A    %7D)%0A%0A    //socket.on('disconnect', function()%7B  //Create disconnect, if client refreshes/exits index.html%0A    //    console.log('user disconnect');%0A    //
 %7D);%0A%7D);%0A
 var 
@@ -613,16 +613,17 @@
 %7D);%0A%7D);%0A
+%0A
 var port
@@ -734,244 +734,8 @@
 rt);
-%0A%0A    /*    MongoClient.connect(url, function (err, db) %7B%0A     if (err) %7B%0A     console.log('Unable to connect to the mongoDB server. Error:', err);%0A     %7D%0A     else %7B%0A     var collection = db.collection('chathistory');%0A     %7D%0A     %7D);*/
 %0A%7D);

Delete dead code