-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow modify and reload configTrust without restart perseo-fe #757
Comments
Suggestion for implementation: const fs = require('fs');
const path = require('path');
const filePath = './yourModule.js'; // Replace with the path to your module
function requireUncached(module) {
delete require.cache[require.resolve(module)];
return require(module);
}
function watchFile() {
fs.watchFile(path.resolve(filePath), { persistent: true, interval: 1000 }, (curr, prev) => {
if (curr.mtime > prev.mtime) {
console.log(`Reloading module '${filePath}'...`);
try {
const updatedModule = requireUncached(filePath);
// Now you can use the updated module
} catch (err) {
console.error('Error reloading module:', err);
}
}
});
}
// Start watching the file for changes
watchFile(); In Node.js, you can use the fs (file system) module along with require.cache to achieve dynamic reloading of a local module when it changes. Here's a simple example: javascriptCopy codeconst fs = require('fs');const path = require('path');
const filePath = './yourModule.js'; // Replace with the path to your modulefunction requireUncached(module) {
delete require.cache[require.resolve(module)];
return require(module);
}
function watchFile() {
fs.watchFile(path.resolve(filePath), { persistent: true, interval: 1000 }, (curr, prev) => {
if (curr.mtime > prev.mtime) {
console.log(`Reloading module '${filePath}'...`);
try {
const updatedModule = requireUncached(filePath);
// Now you can use the updated module } catch (err) {
console.error('Error reloading module:', err);
}
}
});
}
// Start watching the file for changes
watchFile(); In this example: |
Implemented by PR #758 |
reload configTrust.js
#745
The text was updated successfully, but these errors were encountered: