0

I'm trying to open a URL in the browser however the only options I have seen require you have a 'http' within the URL. Im trying to open a localhost from browser. How could I achieve this using nodejs?

Dmitriy_I
  • 65
  • 5
  • In a Windows system, you can execute the node statement `child_process.exec('explorer "http://localhost/..."');` – Heiko Theißen Mar 05 '23 at 08:17
  • check this question https://stackoverflow.com/questions/8500326/how-to-use-nodejs-to-open-default-browser-and-navigate-to-a-specific-url – dom1 Mar 05 '23 at 08:25
  • @dom1 the issue with open is that it requires an HTTP URL, Im trying to access a 'non-http' url ie "localhost:3000", no protocol nothing – Dmitriy_I Mar 05 '23 at 20:22

1 Answers1

1

Use the open npm package

Install it:

npm install open

In your node code:

const open = require('open');
open("localhost:8080");
ProfDFrancis
  • 8,816
  • 1
  • 17
  • 26