JavaScript Automation Hacks I Learned the Hard Way
How I stopped writing repetitive code and let JS do the heavy lifting
JavaScript Automation Hacks I Learned the Hard Way
How I stopped writing repetitive code and let JS do the heavy lifting
When I started working with JavaScript, I thought it was just for making buttons clickable and forms submit. Fast-forward a few years, and I’ve realized it’s an automation powerhouse — whether you’re in the browser, on the server with Node.js, or even wiring up APIs.
This article is my personal playbook: 8 JavaScript automation tricks that made my life (and my projects) smoother. Each section comes with large code blocks and deep dives, so you can take these patterns and run with them.
1. File Automation With Node.js fs
My first “aha” moment with Node.js was realizing I could use it like Python for filesystem automation.
const fs = require('fs');
const path = require('path');
const downloads = './downloads';
const pdfDir = './pdfs';
const imgDir = './images';
[ pdfDir, imgDir ].forEach(dir => {
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
});
fs.readdirSync(downloads).forEach(file => {
const filePath = path.join(downloads, file);
if (file.endsWith('.pdf')) {
fs.renameSync(filePath, path.join(pdfDir, file));
} else if (file.endsWith('.jpg') || file.endsWith('.png')) {
fs.renameSync(filePath, path.join(imgDir, file));
}
});
This script cleaned up my cluttered download folder in seconds. Before that, I was manually dragging files around like it was 2009.
2. Web Scraping With puppeteer
Sometimes the data you need is behind a login screen or hidden in a dynamic site. puppeteer is my go-to.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto('https://quotes.toscrape.com/');
const quotes = await page.$$eval('.text', els => els.map(e => e.innerText));
console.log(quotes);
await browser.close();
})();
This little script logs in, navigates, and scrapes data like a human — but 100x faster.
3. Automating Emails With nodemailer
Once upon a time, I had to send weekly reports to a team. After two weeks of forgetting, I automated it.
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'me@gmail.com',
pass: 'your_app_password'
}
});
const mailOptions = {
from: 'me@gmail.com',
to: 'boss@gmail.com',
subject: 'Weekly Status Report',
text: 'All systems are green ✅'
};
transporter.sendMail(mailOptions, (err, info) => {
if (err) return console.error(err);
console.log('Email sent:', info.response);
});
No more “Did you send the report yet?” messages. The script had my back.
4. Automating API Calls With axios
APIs are where the magic happens. Automating them is like wiring electricity into your apps.
const axios = require('axios');
(async () => {
try {
const response = await axios.get('https://jsonplaceholder.typicode.com/posts');
response.data.slice(0, 5).forEach(post => {
console.log(`${post.id}: ${post.title}`);
});
} catch (error) {
console.error(error);
}
})();
I use this pattern for everything from checking weather APIs to updating Slack channels automatically.
5. CLI Tools With commander
I once built a CLI tool to automate repetitive Git commands. commander made it painless.
const { program } = require('commander');
program
.version('1.0.0')
.description('A simple CLI tool')
.option('-n, --name <type>', 'Add your name')
.action((options) => {
console.log(`Hello, ${options.name || 'world'}!`);
});
program.parse(process.argv);
Now I can type node tool.js -n Alex and instantly get output. Pro tip: wrap boring scripts into CLI tools—it feels like building your own personal toolbox.
6. Task Scheduling With node-cron
I don’t like remembering to run scripts. That’s what cron jobs (and node-cron) are for.
const cron = require('node-cron');
cron.schedule('0 9 * * 1', () => {
console.log('Weekly report task running every Monday at 9 AM');
});
This line schedules a task to run every Monday at 9 AM. Combine this with email automation, and you’re basically on autopilot.
7. Browser Automation With Extensions (Content Scripts)
Sometimes, I build Chrome extensions just to save myself clicks.
// content.js
document.querySelectorAll('a').forEach(a => {
a.style.border = '1px solid red';
});
This silly script highlights all links in red. But in reality, I use content scripts to auto-fill forms and add shortcuts to dashboards I use daily.
8. Reporting With chart.js
Automation isn’t just about scraping and emails — it’s also about presenting the results cleanly.
<canvas id="salesChart"></canvas>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
const ctx = document.getElementById('salesChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['US', 'EU', 'APAC'],
datasets: [{
label: 'Sales',
data: [1000, 800, 1200]
}]
}
});
</script>
With a few lines, you get a dashboard-ready chart. I use this in internal tools to visualize automation results without boring spreadsheets.
Final Thoughts
JavaScript isn’t just the language of the browser — it’s the Swiss Army knife of automation. Whether you’re scraping sites, managing files, sending emails, or generating reports, JS has your back.
What separates good developers from great ones is knowing when to let the machine work for you. Or as one senior engineer told me: “The best code you’ll ever write is the one that deletes hours of manual work.”
So… what’s the first thing you’re going to automate with JavaScript?
메타데이터
- post_id
- 8be8aaa36056
- slug
- javascript-automation-hacks-i-learned-the-hard-way-8be8aaa36056
- url
- https://medium.com/@fordlucas125/javascript-automation-hacks-i-learned-the-hard-way-8be8aaa36056
- canonical_url
- https://medium.com/@fordlucas125/javascript-automation-hacks-i-learned-the-hard-way-8be8aaa36056
- author_url
- https://medium.com/@fordlucas125
- status
- ok
- fetched_at
- 2026-08-26 23:10:29