javascriptnode.jselectronshelljs

Node.js absolute path


I'm trying to build a Electron app which quickly pull the machine info to the user. I'm trying to use the npm module 'shelljs' to be able to use shell script in a node environment. But Electron doesn't really support shelljs so I'm in a bit of a pickle. There is a workaround that includes to use the absolute path to the node binary. Not sure what they mean by that so I thought you guys could help out.


The workaround I got is taken from here where they say this:

Set it like any regular variable.

// This is inside your javascript file

var shell = require('shelljs');
shell.config.execPath = 'path/to/node/binary'; // Replace this with the real path

// The rest of your script...

This is my code where I get an undefined on the execPath:

const shell = require('shelljs')
const path = require('path')
shell.confic.execPath = path.join('C:', 'Program Files', 'nodejs', 'node_modules', 'npm', 'bin')

Am I interpreting the workaround the wrong way?


Solution

  • The spelling error that @Chirag Ravindra pointed out did the trick. After a bit of thinking I came to this solution:

    shell.config.execPath = path.join('C:', 'Program Files', 'nodejs', 'node.exe')
    

    //Thomas