0

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?

RobC
  • 22,977
  • 20
  • 73
  • 80
Thomas Bengtsson
  • 399
  • 2
  • 10
  • 22
  • 1
    I may be wrong but is there a `.bin` folder in `node_modules` folder of your app? The binaries of items stored as deps in `package.json` usually go in there. The also appears to be a typo in `shell.confic.execPath` – Chirag Ravindra Apr 04 '18 at 09:57
  • You can get the path to electron with `process.execPath` so probably `shell.config.execPath = process.execPath`. You can run electron has node by setting the environment variable `ELECTRON_RUN_AS_NODE=1` so in your case `process.env.ELECTRON_RUN_AS_NODE=1` – gman Apr 04 '18 at 10:01

1 Answers1

0

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

Thomas Bengtsson
  • 399
  • 2
  • 10
  • 22