Created
September 4, 2019 07:55
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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