I'm currently writing a node.js app currently using: express, jade, and js-yaml. The YAML parser loads the file that I need to load easily.
require('js-yaml');
var file = require(path);
The contents of the file that I need to get information from is then loaded into the jade template.
app.get('/', function(req, res){
res.render('index', { pageData: contents });
});
Now my problem is that when the information in the YAML file changes, i want the information on the node.js server to update, or refresh the information. As of right now, it loads one time, but that's it. Is there a way to either create a listener or some other type of function to update the information?
Use fs.watchFile() to watch the file for changes and load them as the file changes. You could also use setInterval, to update based on some time inteval.
fs.watchFile(fileName, [array of options], function callback() {
//Whatever actions parse your yaml file here
}