Sometimes, we want to use Node.js to open default browser and navigate to a specific URL.
In this article, we’ll look at how to use Node.js to open default browser and navigate to a specific URL.
How to use Node.js to open default browser and navigate to a specific URL?
To use Node.js to open default browser and navigate to a specific URL, we can use the open
package.
To install it, we run
npm install open
Then we use it by writing
const open = require("open");
open("http://example.com");
open("http://example.com", { app: "firefox" });
to call open
to open the URL we pass into it.
We can also call it with an object that has some options.
We set app
to 'firefox'
to open the URL in Firefox.
Conclusion
To use Node.js to open default browser and navigate to a specific URL, we can use the open
package.