xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Node.js & create file All In One

Node.js & create file All In One

node js create a file if not exists

https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback

fs.open(path[, flags[, mode]], callback)

https://nodejs.org/api/fs.html#fs_file_system_flags

File System Flags

blogs

https://stackoverflow.com/questions/12809068/create-an-empty-file-in-node-js

https://stackoverflow.com/questions/12899061/creating-a-file-only-if-it-doesnt-exist-in-node-js

http://www.technicalkeeda.com/nodejs-tutorials/check-if-file-folder-is-exists-or-not-using-nodejs

https://stackabuse.com/writing-to-files-in-node-js/

https://learnnode.com/



const fs = require('fs');
fs.writeFile("/tmp/test", "Hey there!", function(err) {
    if(err) {
        return console.log(err);
    }

    console.log("The file was saved!");
}); 

https://stackoverflow.com/questions/2496710/writing-files-in-node-js

fs.closeSync(fs.openSync('/var/log/my.log', 'a'));

https://www.tutorialkart.com/nodejs/create-file-in-nodejs-using-node-fs-module/
https://www.w3schools.com/nodejs/nodejs_filesystem.asp

var fs = require('fs');
var stream = fs.createWriteStream("my_file.txt");
stream.once('open', function(fd) {
  stream.write("My first row\n");
  stream.write("My second row\n");
  stream.end();
})


// Just open the file and handle the error when it's not there.



function createFile(filename) {
  fs.open(filename,'r',function(err, fd){
    if (err) {
      fs.writeFile(filename, '', function(err) {
          if(err) {
              console.log(err);
          }
          console.log("The file was saved!");
      });
    } else {
      console.log("The file exists!");
    }
  });
}


Node.js check and create folder All In One

https://stackoverflow.com/questions/21194934/how-to-create-a-directory-if-it-doesnt-exist-using-node-js/71735771#71735771

https://www.cnblogs.com/xgqfrms/p/16155641.html

refs



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2019-05-13 10:07  xgqfrms  阅读(547)  评论(1编辑  收藏  举报