1.0.14 • Published 6 years ago
requirelive v1.0.14
requireLive
requires a file and keeps the file and object updated
example
const requireLive = require('requireLive')
// 'new' event is triggerd whenever a new name is added
requireLive.events.on('new', (name, object) => {
console.log(name, object)
})
// 'update' event is triggerd whenever an object is updated
requireLive.events.on('update', (name, object) => {
console.log(name, object)
})
// require an existing file
const example1 = requireLive('./example1.json')
const example2 = requireLive('./example2.json', {
interval: 1000,
persistent: true,
name: 'example2',
paths: module.paths
})
// example1.json will be updated to include the changes
example1.example = 'true'
// terminal will show current content of example2.json
requireLive.events.on('example2' + 'Update', (object) => {
process.stdout.write('\x1B[2J\x1B[0f') // clear terminal
console.log(example2) // example2 is the same as object
})