Reputation: 956
I have been trying to execute any file in system and open it in the default Application of the system.
For example I have abc.doc file, and i want to open it in Microsoft Word.
This code opens the URL in default browser.
var open = require('open');
open('http://www.google.com', function (err) {
if (err) throw err;
console.log('The user closed the browser');
});
Any suggestion how do I open system files in default application via node js.
Upvotes: 1
Views: 1883
Reputation: 26
In windows you can simply give file path. But in linux or in mac os you need to prefix xdg-open as well to open in default application.
Linux Code & Mac OS
shell.exec("xdg-open /home/file.extension", function (err, out, code)) { /* your statements */ });
Windows Code
shell.exec("C:/file.extension", function (err, out, code)) { /* your statements */ });
Upvotes: 1
Reputation: 2184
use exec from shelljs
Example given below:
var shell = require('shelljs');
shell.exec("D://yourdocument.pdf", function (err, out, code)) {
if(err instanceof Error)
throw err;
});
I hope it helps. Thanks.
Upvotes: 2