Tuesday 16 May 2017

Node: Using fs.readFile getting Error: EISDIR: illegal operation on a directory, read

I have a problem getting fs.readFile to return a css file. I've already read in this SO post that EISDIR error occurs when you try to open a file, but the path given is a directory. But I've checked several times and the console.log inside the getCss function is logging the right path with the correct filename and .css extension. What's the issue? Thanks in advance!

// Path to MUI css
muiCssFile = path.join(muiDistFolder, 'css', 'mui.css'),  


// Read css files
function getCss(callback) {
  console.log('MUI CSS file path in getCss() :: ', muiCssFile);
  // Code fails here.... 
  fs.readFile(muiCssFile, 'utf8', function (err, css) {
    if (err) {
      return callback(err);
    }
    fs.readFile(styleFile, function (error, customCss) {
      if (error) return callback(error);
      callback(null, css + customCss);
    });
  });

}



via mikeym

No comments:

Post a Comment