プログラミング

nodejs asyncでファイル読み込みをする

var fs = require('fs');
var path = require('path');

const util = require('util');
const exec = util.promisify(require('child_process').exec);

var filepath = path.relative( __dirname , "/mnt/c/owncloud_scarlet/note/tmp03.md" ) ; 

const readFile = util.promisify(fs.readFile);

async function getStuff() {
  let data = await readFile( filepath , 'utf8' );
    console.log( data ) ; 
}

getStuff() ; 

or

var fs = require('fs');
var path = require('path');

const util = require('util');
const exec = util.promisify(require('child_process').exec);

var filepath = path.relative( __dirname , "/mnt/c/owncloud_scarlet/note/tmp03.md" ) ; 

const readFile = util.promisify(fs.readFile);

async function getStuff() {
  return await readFile( filepath , 'utf8' ); 
}

getStuff().then(data => {
  console.log(data);
})

node.js – How to read file with async/await properly? – Stack Overflow