fs.writeSync instead of fs.write
added try/catch to complete