This project is a web-based tool that helps users parse and understand cron expressions. Built with a Node.js backend and a Vue.js frontend, it allows users to input a cron expression and view the next 5 execution times.
- Parse cron expressions to determine their validity.
- View the next 5 execution times for valid cron expressions.
- User-friendly interface built with Vue.js and styled with Tailwind CSS.
- Backend powered by Node.js and the
cron-parserlibrary.
cron-expression-parser/
├── backend/
│ ├── server.js # Node.js backend code
│ ├── package.json # Backend dependencies
│
├── frontend/
│ ├── src/
│ │ ├── App.vue # Vue.js main component
│ │ ├── main.js # Vue app initialization
│ ├── package.json # Frontend dependencies
│
├── README.md # Project documentation
- Node.js: Install the latest version from Node.js Official Site.
- npm: Installed automatically with Node.js.
-
Clone the repository:
git clone https://github.com/piehostHQ/cronjob.git cd cron-expression-parser -
Set up the backend:
cd backend npm install node server.js- The backend server will start on
http://localhost:3000.
- The backend server will start on
-
Set up the frontend:
cd ../frontend npm install npm run dev- The frontend will start on
http://localhost:5173.
- The frontend will start on
- Navigate to the frontend in your browser (
http://localhost:5173). - Enter a cron expression (e.g.,
*/5 * * * *). - Click Parse Expression to view the next 5 execution times.
- If the expression is invalid, an error message will be displayed.
The backend is built with Express.js and cron-parser. It provides a POST endpoint /parse-cron to parse the expression.
Example code snippet:
const express = require("express");
const cors = require("cors");
const cronParser = require("cron-parser");
const app = express();
app.use(cors());
app.use(express.json());
app.post("/parse-cron", (req, res) => {
const { cronExpression } = req.body;
try {
const interval = cronParser.parseExpression(cronExpression);
const nextExecutions = [];
for (let i = 0; i < 5; i++) {
nextExecutions.push(interval.next().toString());
}
res.json({ message: "Valid cron expression", nextExecutions });
} catch (error) {
res.status(400).json({ error: "Invalid cron expression" });
}
});
app.listen(3000, () => {
console.log("Backend running at http://localhost:3000");
});The frontend is built with Vue.js and styled using Tailwind CSS. It includes a simple form to input cron expressions and displays results dynamically.
Example template snippet:
<template>
<div>
<input v-model="cronExpression" type="text" placeholder="* * * * *" />
<button @click="parseCron">Parse Expression</button>
<div v-if="errorMessage">{{ errorMessage }}</div>
<ul v-if="nextExecutions.length">
<li v-for="(execution, index) in nextExecutions" :key="index">{{ execution }}</li>
</ul>
</div>
</template>
<script>
import axios from "axios";
export default {
data() {
return {
cronExpression: "",
nextExecutions: [],
errorMessage: "",
};
},
methods: {
async parseCron() {
try {
const response = await axios.post("http://localhost:3000/parse-cron", { cronExpression: this.cronExpression });
this.nextExecutions = response.data.nextExecutions;
} catch (error) {
this.errorMessage = error.response?.data?.error || "Invalid cron expression.";
}
},
},
};
</script>Here are some ideas to extend this project:
-
Human-readable Descriptions:
- Convert cron expressions into natural language (e.g., "Every 5 minutes").
-
Integration with Task Schedulers:
- Use the backend to schedule actual tasks (e.g., reminders or emails).
-
Improved Validation:
- Add frontend validation for cron expressions before sending them to the backend.
-
Styling Enhancements:
- Use a modern design system like Vuetify or Bootstrap for advanced UI components.