Answers for "node write file from buffer"

16

writefile in node js

// writefile.js

const fs = require('fs');

let lyrics = 'But still I\'m having memories of high speeds when the cops crashed\n' + 
             'As I laugh, pushin the gas while my Glocks blast\n' + 
             'We was young and we was dumb but we had heart';

// write to a new file named 2pac.txt
fs.writeFile('2pac.txt', lyrics, (err) => {
    // throws an error, you could also catch it here
    if (err) throw err;

    // success case, the file was saved
    console.log('Lyric saved!');
});
Posted by: Guest on March-15-2020
0

nodejs write raw buffer to file

/*
	Using nodejs' fs module you can create a WriteStream
    to handle raw stream of bytes and buffers.
*/

const path = "path/to/the/file";

array = BigInt64Array(0);
buffer = Buffer.from(array.buffer)

fs.createWriteStream(path).write(buffer);
Posted by: Guest on June-19-2021
0

write buffer to file in node

fs = require('fs');
fs.writeFile('helloworld.txt', 'Hello World!', function (err) {
  if (err) return console.log(err);
  console.log('Hello World > helloworld.txt');
});
Posted by: Guest on April-19-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language