Launch VLC from an Electron app

Let's assume that you try to execute VLC from the Electron main process. You can use child_process module:

const { app, BrowserWindow, dialog } = require('electron');
const { spawn }                      = require('child_process');

function createWindow () {
    const win = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
          nodeIntegration: true

function launchVLC () {
    // Specifying path in Windows
    const path = 'C:\\Program Files\\VideoLAN\\VLC\\vlc.exe';
    // Launching VLC
    const proc = spawn(`"${path}"`, [``], { shell: true });


In Windows, you need to specify the full path to launch the application, while in Linux or macOS, you could do the following:

function launchVLC () {
    const proc = spawn(`vlc`, [``], { shell: true });

I'm not quite sure if there is a better solution to launch VLC in one line of code that works in Windows, Linux, and macOS. Please, tell me if you find it!

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.