open a file with default program in node-webkit
You can use the open module:
npm install --save open
and then call it in your Node.js file:
const open = require('open');
open('my-file.txt');
This module already contains the logic to detect the operating system and it runs the default program that is associated to this file type by your system.
as PSkocik said, first detect the platform and get the command line :
function getCommandLine() {
switch (process.platform) {
case 'darwin' : return 'open';
case 'win32' : return 'start';
case 'win64' : return 'start';
default : return 'xdg-open';
}
}
second , execute the command line followed by the path
var exec = require('child_process').exec;
exec(getCommandLine() + ' ' + filePath);
For file on a disk:
var nwGui = require('nw.gui');
nwGui.Shell.openItem("/path/to/my/file");
For remote files (eg web page):
var nwGui = require('nw.gui');
nwGui.Shell.openExternal("http://google.com/");