fs.watch( 'example.xml', function ( curr, prev ) {
// on file change we can read the new xml
fs.readFile( 'example.xml','utf8', function ( err, data ) {
if ( err ) throw err;
console.dir(data);
console.log('Done');
});
});
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
- 一些数据
- 完成X 1
- 一些数据
- 完成X 2
这是我的使用错误还是..?
我是node.js和java脚本的新手,我找不到这个".on"关键字的含义.当我用另一个单词代码更改失败时.
var req = http.get("http://www.google.com", function(res) {
console.log("Got response: " + res.statusCode);
res.on('data', function (chunk) {
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
Run Code Online (Sandbox Code Playgroud)