Automation

Automate weekly sales reports with Node.js

From three hours of consolidating Excel every Monday morning to an automated email at 7 AM. How I built a simple, maintainable workflow.

Biểu đồ doanh thu tuần và cron job gửi báo cáo tự động bằng Node.js
In this article

    A retail customer spends three hours every Monday morning pulling data from websites, e-commerce platforms, and accounting software into an Excel file. Here is how we automated that.

    Gathering data from sources

    Each source has its own module, returning the same format: date, channel, revenue, order count. Adding a new source simply requires writing another module.

    const sources = [woocommerce, marketplace, accounting];
    const rows = (await Promise.all(
      sources.map(s => s.fetchWeek(lastMonday))
    )).flat();

    Aggregation and verification

    Before sending, the script compares the total revenue with the previous week. If there is an unusual discrepancy, the report is flagged with a warning for the recipient to double-check the data source.

    Delivering on time

    A cron job runs at 7 AM every Monday, generating the Excel file and emailing it to the management board. No dedicated server is needed—a serverless function is enough.

    Result: saves about 150 hours per year, and no more data errors from copy-pasting.

    Start small

    Do not try to automate everything at once. Pick the most repetitive report, automate it, and then gradually expand.

    Tags:Báo cáoNode.jsTự động hoá
    Gnurt

    Full-stack developer

    Discuss your project