-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
41 lines (34 loc) · 1.17 KB
/
main.js
File metadata and controls
41 lines (34 loc) · 1.17 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
const PORT = process.env.PORT || 3000;
const server = require('http').createServer(service);
const io = require('socket.io')(server);
const mongoose = require('mongoose');
const configuration = require('./configurations/mongodb');
mongoose.connect(configuration.mongolab);
function service (request, response) {
readFile ('./main.html').then(function (file) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(file);
response.end();
})
}
function readFile(file) {
const filesystem = require('fs');
function promise (resolve, reject) {
filesystem.readFile(file, function (error, data) {
if (error) reject(error);
else if (data) resolve(data);
else reject();
});
}
return new Promise(promise);
}
mongoose.connection.on('connected', function() {
console.log('MongoDB is up and running...');
require('./application/sockets')(io);
server.listen(PORT, function () {
console.log("Up and running @ localhost: " + PORT);
});
});
mongoose.connection.on('error', function(error) {
console.error('Error in connecting MongoDB: ' + error);
});