0
我喜歡更新node.js中的JavaScript文件(模塊),然後保存它。我有以下js模塊。如何修改一個js文件,然後將其保存迴文件?
var test = {
scripts: ["a.js","b.js"],
getScripts: function()
{
return this.scripts;
}
}
module.exports = test;
我喜歡在其他模塊中加載上述模塊,然後更新腳本數組,然後將其保存迴文件。我試圖使用JSON.stringify(測試),但它不保留getScripts方法。
這是否存在破解或詭計?
只要你有這種感覺,你最好'JSON.stringify'''腳本'數組到文件。在您的節點模塊中,使用序列化數組[注意文件](http://nodejs.org/api/fs.html#fs_fs_watchfile_filename_options_listener)。 – elmigranto