TimeCollect.js is a Node.js web application designed to automate the collection and processing of timesheet data from Google Sheets BPG Timesheet. It aggregates data from multiple employee sheets, transforms it into a structured format, generates a consolidated Excel exported data, and automatically uploads it to a specified folder in Google Drive.
- Automated Data Fetching : Connects to the Google Sheets API to pull data from multiple timesheets.
- Data Transformation : Cleans, structures, and aggregates timesheet entries into a single dataset.
- Excel Report Generation : Creates a
.xlsxfile from the processed data usingexceljs. - Google Drive Integration : Automatically uploads the final report to a designated Google Drive folder, updating the existing file if it's already there.
- Web Interface : A simple UI with a single button to trigger the entire process and a log panel to monitor progress.
- Backend : Node.js, Express.js
- APIs : Google Sheets API v4, Google Drive API v3
- Key Libraries :
googleapisfor Google API interaction.exceljsfor creating Excel files.dotenvfor environment variable management.
Follow these instructions to get a copy of the project up and running on your local machine.
- Node.js (v18.x or later recommended)
- A Google Cloud Platform project with a configured Service Account.
-
Clone the repository
git clone https://github.com/your-username/timecollect.js.git cd timecollect.js -
Install dependencies
npm install -
Google Cloud Setup
- Ensure you have a Google Cloud project created.
- In your project, enable the Google Sheets API and the Google Drive API .
- Create a Service Account and download its JSON key file.
- Rename the downloaded key to
credentials.jsonand place it inside the/google_credentialsdirectory. - Share your Google Sheets with the service account's email address as a Viewer .
- Create a target folder in Google Drive and share it with the service account's email as an Editor .
-
Configure Environment Variables
- Create a
.envfile in the root of the project. You can copy the example below. - Fill in the required values for your project.
Code snippet
# .env file # Application Port PORT=3000 # Dataset Configuration for week types DATASET_YEAR=2024 DATASET_MONTH=12 DATASET_DAY=29 # Sheet Names to process (comma-separated) SHEET_NAMES=202509,202510 # Google Sheet IDs and Ranges PROJECT_SPREADSHEET=your_project_spreadsheet_id_here PROJECT_RANGE=Sheet1!A:C EMPLOYEES_SPREADSHEET_2025=your_employees_spreadsheet_id_here OUTPUT_DIRECTORY=./output # Google Drive Folder ID # Get this from the URL of your target folder in Google Drive GOOGLE_DRIVE_FOLDER_ID=your_folder_id_here - Create a
-
Start the server
npm startThe application will be running at
http://localhost:3000. -
Run the process
- Open your web browser and navigate to
http://localhost:3000. - Click the "Process Timesheets" button.
- Monitor the progress in the log panel on the webpage and in your terminal.
- Upon completion, the
TimeCollect.xlsxfile will be saved locally in the/outputdirectory and uploaded to your specified Google Drive folder.
- Open your web browser and navigate to
This project is set up with Jest for automated testing.
-
Install testing dependencies (if you haven't already)
npm install --save-dev jest supertest -
Run tests
npm test