We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies. Learn More
contact@techquestworld.com
+919547614783
Premium Article
Published 4 months ago

Automate Your Day with JavaScript – Fast & Easy

5 min read
381 views
Automate Your Day with JavaScript – Fast & Easy
Photo by Techquestworld

Learn how to automate your everyday repetitive tasks using JavaScript. Explore 10 real automation scripts that save hours weekly from cleaning files to sending reminders.

🔹 Why Automate with JavaScript?

• Cross-platform with Node.js

• Easily schedule with cron or npm packages

• Ideal for developers already using JS

• Replaces manual scripts and boosts productivity

10 Daily Tasks I Automate Using JavaScript

1. ✅ Auto-Clean Old Files from Downloads Folder

const fs = require('fs');
const path = require('path');

const folderPath = '/Users/yourname/Downloads';
const daysOld = 7;
const now = Date.now();

fs.readdir(folderPath, (err, files) => {
files.forEach(file => {
const filePath = path.join(folderPath, file);
fs.stat(filePath, (err, stats) => {
const diffTime = (now - stats.ctimeMs) / (1000 * 3600 * 24);
if (diffTime > daysOld) fs.unlinkSync(filePath);
});
});
});

Why: Frees space automatically, no more clutter.

2. 📧 Daily Email Reminder Using NodeMailer

const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'youremail@gmail.com',
pass: 'yourpassword'
}
});

transporter.sendMail({
from: 'youremail@gmail.com',
to: 'receiver@example.com',
subject: 'Daily Reminder',
text: 'Don't forget to write your blog today'
})

Why: Keeps your goals top of mind, daily.

3. 🔎 Check Website Uptime with Axios

const axios = require('axios');

axios.get('https://techquestworld.com')
.then(res => console.log('Website is UP'))
.catch(err => console.log('Website is DOWN'));

Why: Uptime monitoring = peace of mind.

4. 📅 Auto-Google Calendar Reminder (with Google API)

a. Install Required Packages

npm install googleapis dotenv

b. Create .env File

GOOGLE_CLIENT_ID=your_client_id
GOOGLE_CLIENT_SECRET=your_client_secret
GOOGLE_REDIRECT_URI=https://developers.google.com/oauthplayground
GOOGLE_REFRESH_TOKEN=your_refresh_token

You can get these credentials from Google Cloud Console and use OAuth 2.0 Playground to generate the refresh token.

c. Create calendar.js File

require('dotenv').config();
const { google } = require('googleapis');

// Set up OAuth2 client
const oAuth2Client = new google.auth.OAuth2(
process.env.GOOGLE_CLIENT_ID,
process.env.GOOGLE_CLIENT_SECRET,
process.env.GOOGLE_REDIRECT_URI
);

oAuth2Client.setCredentials({ refresh_token: process.env.GOOGLE_REFRESH_TOKEN });

// Initialize Calendar API
const calendar = google.calendar({ version: 'v3', auth: oAuth2Client });

// Define your event
const event = {
summary: 'Morning Reminder: Check Emails & Plan Tasks',
location: 'Your Desk',
description: 'Automated daily reminder using Google Calendar API',
start: {
dateTime: '2025-05-27T06:00:00+05:30', // 6 AM IST
timeZone: 'Asia/Kolkata',
},
end: {
dateTime: '2025-05-27T06:30:00+05:30', // 30 minutes
timeZone: 'Asia/Kolkata',
},
reminders: {
useDefault: false,
overrides: [
{ method: 'popup', minutes: 10 },
],
},
};

// Insert the event
calendar.events.insert(
{
calendarId: 'primary',
resource: event,
},
(err, res) => {
if (err) {
console.error('Error creating event:', err);
return;
}
console.log('✅ Event created successfully:', res.data.htmlLink);
}
);

Why: Never miss a meeting again.

5. 🧹 Clear Cache and Temp Files

const tempPath = '/Users/yourname/temp';
// Use fs.unlink() like the first example

Why: Keeps your system fast.

6. 📂 Auto-Sort Files by Type Using Node.js

a. Setup Project

mkdir auto-file-sorter
cd auto-file-sorter
npm init -y
npm install fs path

b. sortFiles.js

const fs = require("fs");
const path = require("path");

// 🔧 Source folder path
const folderPath = path.join(__dirname, "downloads");

// 📂 File type categories
const fileTypes = {
images: [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".svg", ".webp"],
videos: [".mp4", ".avi", ".mov", ".mkv", ".webm"],
documents: [".pdf", ".docx", ".doc", ".xlsx", ".pptx", ".txt"],
music: [".mp3", ".wav", ".aac", ".flac"],
archives: [".zip", ".rar", ".7z", ".tar", ".gz"],
code: [".js", ".html", ".css", ".py", ".php", ".java", ".c", ".cpp", ".ts"]
};

// ✅ Create folder if not exists
const ensureFolder = (folderName) => {
const folder = path.join(folderPath, folderName);
if (!fs.existsSync(folder)) fs.mkdirSync(folder);
return folder;
};

// 🚀 Auto-sort function
const sortFiles = () => {
fs.readdir(folderPath, (err, files) => {
if (err) return console.log("❌ Error reading folder:", err);

files.forEach(file => {
const ext = path.extname(file).toLowerCase();
const fromPath = path.join(folderPath, file);

if (fs.lstatSync(fromPath).isDirectory()) return; // Skip folders

let moved = false;

// 🔍 Match file type and move
for (const [type, extensions] of Object.entries(fileTypes)) {
if (extensions.includes(ext)) {
const toFolder = ensureFolder(type);
const toPath = path.join(toFolder, file);
fs.renameSync(fromPath, toPath);
console.log(`✅ Moved ${file} → ${type}/`);
moved = true;
break;
}
}

// 📦 Uncategorized
if (!moved) {
const othersFolder = ensureFolder("others");
fs.renameSync(fromPath, path.join(othersFolder, file));
console.log(`📦 Moved ${file} → others/`);
}
});
});
};

sortFiles();

Run:

node sortFiles.js

Why: Keeps your workspace organized.

7. 🧾 Daily Expense Logger with File Write

const fs = require('fs');
fs.appendFileSync('expenses.txt', `Food: $10 - ${new Date().toLocaleDateString()}\n`);

Why: Quick logging helps track your budget.

8. 🎵 Auto-Play YouTube Playlist at 6 AM (with Puppeteer)

a. Install Required Packages

npm install puppeteer node-schedule
youtubePlaylistAutoPlayer.js
const puppeteer = require('puppeteer');
const schedule = require('node-schedule');

// Your YouTube playlist URL
const playlistURL = 'https://www.youtube.com/playlist?list=YOUR_PLAYLIST_ID';

async function autoPlayPlaylist() {
const browser = await puppeteer.launch({
headless: false, // To see the browser window
defaultViewport: null,
args: ['--start-maximized']
});

const page = await browser.newPage();
await page.goto(playlistURL, { waitUntil: 'networkidle2' });

// Accept cookies if prompted
try {
await page.click('button[aria-label="Accept all"]', { timeout: 3000 });
} catch (e) {
// No cookie banner
}

// Click the "Play All" button
try {
await page.waitForSelector('ytd-playlist-video-renderer', { timeout: 5000 });
console.log('Playlist loaded. Autoplay will begin.');
} catch (err) {
console.log('Could not find playlist or play button.');
}
}

// 🎯 Schedule the function to run at 6:00 AM every day
schedule.scheduleJob('0 6 * * *', () => {
console.log('⏰ Launching YouTube Playlist at 6 AM...');
autoPlayPlaylist();
});

// Run immediately if you want to test
autoPlayPlaylist();

Why: Start your day with a boost.

9. 📈 Fetch Stock Prices (or Crypto Rates)

axios.get('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd')
.then(res => console.log(`BTC: $${res.data.bitcoin.usd}`));

Why: Daily investment check-in made easy.

10. 🔔 Desktop Notification for Break Reminder

const notifier = require('node-notifier');
notifier.notify('Time to stretch and rest your eyes');

Why: Prevent burnout and fatigue.

Bonus: Automate with Cron

Use node-cron to schedule these scripts daily:

const cron = require('node-cron');
cron.schedule('0 8 * * *', () => {
console.log('Running daily automation...');
});

Try one script today. Comment below which task you'll automate first. Subscribe to TechQuestWorld for weekly developer hacks.

Author
TAPAS SAHOO

Developer by Profession, Techie by Heart

A curious mind with a love for writing and technology, dedicated to simplifying web development and programming topics while keeping up with the ever-changing tech landscape.

Discussion (0)

Replying to
Previous Article
Node.js + AI: Creating Smart Backend Applicat...

Learn how to harness the power of AI in your Node.js backend appli...

Next Article
Fix CORS Policy Error in Node.js – 5 Proven S...

Struggling with CORS errors in your Node.js app? Here's a guide with 5 proven solutions and complete...

Related Articles

Lost Your Keys? That's Linear Search in JavaScript
Lost Your Keys? That's Linear Search in JavaScript

Learn Linear Search in JavaScript the fun way! If you're just starting out, this guide walks you thr...

Build a To-Do List in JavaScript – Beginner Friendly with Source Code
Build a To-Do List in JavaScript – Beginner Friend...

Develop a fully-featured To-Do app from scratch using only vanilla JavaScript—perfect for sharpening...

Modern Table View with Select All & Delete Button Using JavaScript | TechQuestWorld
Modern Table View with Select All & Delete Button...

Build a sleek, responsive table with a Select All checkbox and Delete Selected Rows functionality us...

Stay Ahead: The Top JavaScript Libraries Making Waves in 2025
Stay Ahead: The Top JavaScript Libraries Making Wa...

Explore the top 5 JavaScript libraries in 2025 that are changing how developers build fast, scalable...

Table of Contents