Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Created September 4, 2019 07:55
Show Gist options
  • Save jonschlinkert/ff5557524b1bee7ea24ef57d199ddfe7 to your computer and use it in GitHub Desktop.
Save jonschlinkert/ff5557524b1bee7ea24ef57d199ddfe7 to your computer and use it in GitHub Desktop.
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