Answers for "node js create file"

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
1

create file in nodejs

fs.writeFile('<fileName>',<contenet>, callbackFunction)
Posted by: Guest on August-08-2021
0

create file node javascript

var fs = require('fs');

fs.open('mynewfile2.txt', 'w', function (err, 
  file) {
  if (err) throw err;
  console.log('Saved!');
});
Posted by: Guest on September-09-2021
3

fs create or edit file

//Edit file or creates if doesnt exist
 const fs = require('fs');
 fs.appendFile(‘<fileName>’,<content>,callbackFunction)
Posted by: Guest on April-01-2020
1

writefile in node js

// write_stream.js

const fs = require('fs');

let writeStream = fs.createWriteStream('secret.txt');

// write some data with a base64 encoding
writeStream.write('aef35ghhjdk74hja83ksnfjk888sfsf', 'base64');

// the finish event is emitted when all data has been flushed from the stream
writeStream.on('finish', () => {
    console.log('wrote all data to file');
});

// close the stream
writeStream.end();
Posted by: Guest on March-15-2020
0

create file object node js

var imagePath = path.join('/images/logo.png', 'logo.png');

  if (fs.statSync(imagePath)) {
     var bitmap = fs.readFileSync(imagePath);
     var bufferImage = new Buffer(bitmap);

     Magic = mmm.Magic;
     var magic = new Magic(mmm.MAGIC_MIME_TYPE);
     magic.detectFile(imagePath, function(err, result) {
          if (err) throw err;
          datas = [{"buffer": bufferImage, "mimetype": result, "originalname": path.basename(imagePath)}];
          var JsonDatas= JSON.parse(JSON.stringify(datas));
          log.notice(JsonDatas);
     });
 }
Posted by: Guest on August-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language