From f871d7483f278d245f095f20529e7447ab751eb0 Mon Sep 17 00:00:00 2001 From: jkaplon Date: Thu, 18 Feb 2016 18:03:22 -0500 Subject: [PATCH] Overwriting contents of allNotes.txt with changes from client. --- server.js | 16 ++++++++++++---- views/index.hbs | 5 +---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/server.js b/server.js index 7b5093b..0426972 100644 --- a/server.js +++ b/server.js @@ -40,13 +40,21 @@ app.get('/', function(req, res){ app.post('/', function(req, res){ winston.info('POST received'); - // Stage and commit changes to allNotes.txt. // quick/dirty poc is to do a fileSystem.write to create a new file w/contents of req.body! - var now = Date.now(); - fileSystem.writeFile(__dirname + '/note-data/test-' + now + '.txt', req.body, function(err){ + //var now = Date.now(); + //fileSystem.writeFile(__dirname + '/note-data/test-' + now + '.txt', req.body, function(err){ + //if (err) { winston.error(err); } + //winston.info('new test file written'); + //}); + // Overwrite allNotes.txt with new contents from client. + fileSystem.readFile(notePath, 'utf-8', function(err, data){ if (err) { winston.error(err); } - winston.info('new test file written'); + fileSystem.writeFile(notePath, req.body, 'utf-8', function(err) { + if (err) { winston.error(err); } + winston.info('new contents from client written to allNotes.txt'); + }); }); + // Stage and commit changes to allNotes.txt. res.status(204).send('POST received'); }); diff --git a/views/index.hbs b/views/index.hbs index 9f8d473..9aa0a0e 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -29,18 +29,15 @@ var typingTimer; editor.on("changes", function() { - //console.log("changes fired"); clearTimeout(typingTimer); typingTimer = setTimeout( function() { - //alert("saved now!"); - //post('/', editor.getValue()); console.log(editor.getValue()); var request = new XMLHttpRequest(); request.onreadystatechange = function () { var DONE = this.DONE || 4; if (this.readyState === DONE){ - alert(request.responseText); + console.log('ajax is done.'); } }; request.open('POST', '/', true);