Platform/env issue? force url to open in browser - node.js, opn


#1

Not sure if this is a platform issue, but I have been unable to get opn (https://github.com/sindresorhus/opn) or any other “open a url via node.js” module to work within my glitch server.

My code follows the basic format:

 opn('https://tamagotchi-production.glitch.me/start', {app: 'chrome'})
    .catch(err => console.log(err));

I receive an error regardless of whether or not I define the browser to be used (above I’m defining chrome). These errors are similar though differ slightly depending on the module, and from what I’ve been able to find they seem to have to do with the node.js environment, so my question is - has anyone found a way to force-open a url on a glitch server using opn or another module?

I haven’t seen any projects or questions about this, but I could have missed some in my searches so I apologize in advance if this is a repeat-question.

Thank you in advance for any help!!


#2

My understanding is that this type of module opens the browser on the host where the code is - on Glitch that would be the container it’s running on. The container doesn’t have a browser installed, but even if it did you couldn’t see it.

What were you hoping it would do, open the browser on your local computer?


#3

Hi, yes, I’m just trying to open a link in the user’s default browser on their machine - is there a recommended way to go about doing that? @Gareth any resources/direction you can provide would be really appreciated


#4

Try using the window object if your using the javascript-html DOM


#5

Unfortunately I need to do this via back-end code, so I will have to find a workaround. Thanks for the help.


#6

Is there anyway to pass it to the front, though file system, looking for a file or something


#7

I ended up using a combination of api calls instead - thank you for all of your help/suggestions!