Commit a615f5cc authored by Bady's avatar Bady
Browse files

Add feature to store data to external file

parent 66260d90
......@@ -201,4 +201,4 @@ tags
# End of https://www.gitignore.io/api/vim
# config file
config
config.js
\ No newline at end of file
module.exports = {
port: 3000,
filename: "knowledge.json",
username: "treehouse",
password: "fsc2kMod!"
}
var config = require('./config');
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var path = require('path');
var port = process.env.PORT || 3000;
var fs = require('fs')
var port = config.port || 3000;
var filename = config.filename || 'knowledge.json';
var filepath = path.join('/tmp', filename);
//asking server to listen to 3000
server.listen(port, () => {
console.log('Server listening at port %d', port);
console.log('Server listening at port %d', port);
});
//assign static path to public folder
......@@ -51,6 +55,10 @@ user.on('connection', (socket) => {
};
io.emit('leaf data', leafdata);
io.of('mod').emit('leaves data', leavesdata);
fs.writeFileSync(filepath, JSON.stringify(leavesdata), function(err) {
if(err) return console.error(err);
})
});
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment