O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing a service to navigate through directories

Other modules, such as FileListView, DirListView, and TitleBarPath, consume the data from the filesystem, such as directory list, file list, and the current path. So we need to create a service that will provide this data:

./js/Service/Dir.js

const fs = require( "fs" ),       { join, parse } = require( "path" );  class DirService  {    constructor( dir = null ){     this.dir = dir || process.cwd();   }    static readDir( dir ) {     const fInfoArr = fs.readdirSync( dir, "utf-8" ).map(( fileName ) => {       const filePath = join( dir, fileName ),             stats = DirService.getStats( filePath );       if ( stats === false ) {         return false;       }       return {         fileName,         stats       };     });  return fInfoArr.filter( item => item !== ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required