Open an external file using the default OS application (docx with Word, etc.) Using NodeJS and Electron

I am using NodeJS / Electron for a desktop application.

What I want to do is open a file with its default OS application, for example .docx with Word.

What I have tried so far are approaches using child_process.spawn, .exec or .execFile, but I am not getting anything.

Here is my actual code:

var fs = require('fs'),
    cp = require('child_process');

cp.spawn(__dirname + '/test.docx');

Thanks in advance.

+4
source share
1 answer

Use the function openItem()provided by the Electron module shell, for example:

const shell = require('electron').shell;
const path = require('path');

shell.openItem(path.join(__dirname, 'test.docx'));

shell /, .

+12

All Articles