From 671d0a3b693e4f13f5b77956bef49c4c148aa27e Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sat, 14 Jul 2018 05:00:27 -0400 Subject: [PATCH] Log all packets recieved on server --- server.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 7986554..1f933ab 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,7 @@ const WebSocket = require('ws'); -let net = require('net'); -let aprs = require("aprs-parser"); +const net = require('net'); +const aprs = require("aprs-parser"); +const fs = require('fs'); const parser = new aprs.APRSParser(); const client = new net.Socket(); @@ -27,8 +28,11 @@ client.on('data', function(data) { if (!packet.startsWith('#')) { // ignore comments let message = parser.parse(packet); let date = new Date(); + let datestamp = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(); message.recieved = date; console.log(message); + fs.appendFile("log" + datestamp + ".json", JSON.stringify(message) + ",\n", + err => {if (err) throw err;}); wss.broadcast(JSON.stringify(message)); } });