Auto-Open URLs with Node.js – A Beginner-Friendly Script
Want to automate opening a specific URL in your browser multiple times? Whether you're testing link behavior, demoing an app, or running an automation sequence — this simple Node.js script does the job.
๐ ️ What This Script Does
- Opens any given URL in Chrome or Edge
- Lets you choose how many times (tabs) you want it to open
- Works from the command line with just one command
๐ฆ Prerequisites
- Node.js installed on your system
- Install the
openpackage via terminal:
npm install open
๐ก The Node.js Script
Create a file named index.js and paste the code below:
// index.js
const open = require("open").default;
// ๐ URL to open
const url =
"https://hiddengemsatlas.blogspot.com/2025/08/auto-open-urls-with-nodejs-beginner.html"; // Replace this with your URL
// ✅ Map browser IDs to app names
const browserMap = {
1: "chrome",
2: "msedge",
};
// ๐งพ Get command-line arguments
const [, , browserIdArg, countArg] = process.argv;
const browserId = parseInt(browserIdArg);
const count = parseInt(countArg);
// ❌ Validate inputs
if (!browserMap[browserId] || isNaN(count) || count <= 0) {
console.error("❌ Usage: node index.js <browser_id> <number_of_tabs>");
console.log(" Browser IDs: 1 - Chrome, 2 - Edge");
process.exit(1);
}
const selectedBrowser = browserMap[browserId];
(async () => {
console.log(`๐ Opening ${url} in ${selectedBrowser}, ${count} time(s)...`);
for (let i = 0; i < count; i++) {
console.log(`๐งญ Opening tab ${i + 1}`);
await open(url, { app: { name: selectedBrowser } });
}
console.log("✅ All tabs opened.");
})();
๐ How to Run
Open terminal in your project folder and run:
node index.js 1 3
Explanation:
1= Chrome (use2for Edge)3= Number of tabs to open
๐ Use Cases
- Automatically open your blog or product page
- Simulate link click behavior during UI testing
- Preview marketing links or web apps multiple times
๐ฏ Pro Tip
Want a more advanced version that auto-scrolls the page, supports custom configs, and even auto-launches with one click?
Check out our advanced tool on Gumroad:
HGDevHub – Automated URL Viewer (Basic Edition)
๐ฃ I’d Love to Hear From You!
Found this script useful? Have suggestions or a related topic you’d like me to explore? I’d love to hear your feedback and recommendations.
๐ Stay connected and follow HGDevHub for more micro tools, automation scripts, and tech walkthroughs:
- ๐ฆ Follow on X (Twitter)
- ✍️ Follow on Medium
- ๐️ Explore tools on Gumroad
- ๐ฅ Join the Reddit space (Coming Soon)
๐ฌ Your input helps shape what comes next!
๐ฉ Stay Tuned
More automation scripts and micro-tools coming soon. Follow HGDevHub for fresh tools that save time and spark ideas.
Super helpful and well-explained! ๐ฅ Really appreciate how you kept it simple yet practical — great for quick tests, demos, and automation setups. I’m definitely going to adapt this into some of my own workflows. Loved the real-world examples too ๐
ReplyDeleteGreat automation script! Tried it out and it’s working perfectly. Thanks for sharing such a helpful and beginner-friendly blog. Keep up the great work!
ReplyDeleteAwesome tutorial! Loved how beginner-friendly the script was while still being really practical. Perfect for anyone looking to automate URL opening with Node.js.
ReplyDelete