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

Command-line options

Other file managers usually accept command-line options. For example, you can specify a folder when launching Windows Explorer. It also responds to various switches. Let's say that you can give it switch /e, and Explorer will open the folder in expanded mode.

NW.js reveals command-line options as an array of strings in nw.App.argv. So, we can change the code of the DirService initialization in the main module:

./js/app.js

const dirService = new DirService( nw.App.argv[ 0 ] );

Now, we can open a specified folder in the File Explorer straight from the command line:

npm start ~/Sandbox

In UNIX-based systems, the tilde means user home directory. The equivalent in Windows will be as follows:

npm start %USERPROFILE%Sandbox ...

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