fs.writeFileSync replacement for regular javascript

I am using a code library who's examples use Node.js to write a file to the local file system, like this:

fs.writeFileSync('test2.mid', file.toBytes(), 'binary');

I am not using Node.js in my project, so i want to make this a js variable that is base64 string instead of a physical file. How can I do this using only javascript?

file.toBytes() is a function that returns bytes of data to write file. Any help is appreciated!