node - fs.writeFile creates a blank file

后端 未结 5 1559
北荒
北荒 2020-12-19 05:03

I\'m trying to write a new file inside a grunt-search callback.

The process takes and object, traverses through it for some data, creates a new array, and then write

5条回答
  •  隐瞒了意图╮
    2020-12-19 05:14

    Your problem should be that the fs.writeFile starts "asynchronous". Try to change the localArray in here (hardcode it to see if it works):

    fs.writeFile( 'i18n/localize_template.json', localArray, callback)
    

    And there it should work. The solution i think it is that you should use fs.writeFileSync, or to initialize the localArray outside the oncomplete function, before it starts.

提交回复
热议问题