Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple function for "recording" events and persisting them to the file system. Useful for debugging.
'use strict';
const fs = require('fs');
const path = require('path');
module.exports = name => {
const datapath = path.join(__dirname, `${name}.json`);
const history = [];
const record = (input, key) => {
history.push({ input, key });
};
const save = () => {
fs.writeFileSync(datapath, JSON.stringify(history, null, 2));
};
return { record, save };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment