In a nodeJs app I have:


var execSync = require ('child_process'). execSync;

function puts (error, stdout, stderr) {console.log (stdout)}

function execute (comm) {execSync (comm, puts); }

execute ("xdg-open file:///home/pi/index.html");


This works fine when I perform: node myApp.js causes the desired page to open in Chrome.

But: sudo node myApp.js opens the page in Geany !!

If I log in as "root" it is also Geany that opens !!

Many nodeJs modules (which use GPIO) unfortunately require the use of 'sudo'!

What do I do?

  • To put it simple: sudo xdg-open file:///home/pi/index.html (from terminal) opens Geany not Chrome. I read somewhere that deleting: ~/.config/mimeapps.list will solve the problem. It did not!!!! – Poul Christoffersen Jan 18 at 19:26
  • 1
    Could you format the code in your question so that it's distinguishable from regular text? – Dmitry Grigoryev Jan 19 at 16:41

Try setting the default application for root to the same value as for pi:

filetype=$(xdg-mime query filetype file:///home/pi/index.html)
defaultapp=$(xdg-mime query default $filetype) # query as pi
sudo xdg-mime default $defaultapp $filetype    # set as root

Alternatively, executing sudo -u pi xdg-open file:///home/pi/index.html should use the settings of the pi user when opening the file.

Finally, there's a whole bunch of tools you could use instead of xdg-open, e.g. mimeo.

  • Thanks. Your first suggestion : In which file do I put this? Your second suggestion : It does not work for me. The last one: I will look into it. Thanks again / Poul C – Poul Christoffersen Jan 30 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.