Sure, here is a concise README.md
file with step-by-step instructions:
# Spreadsheet API with Google Sheets and MongoDB Logging
This project is a Node.js application that integrates with the Google Sheets API and logs data to MongoDB using Winston.
## Prerequisites
- Node.js (v16.17.0)
- npm (v9.6.4)
- Google Cloud project with OAuth2 credentials
- MongoDB instance (Atlas or local)
## Setup
### 1. Clone the Repository
```bash
git clone https://github.com/mfarkhanpratama/SpreadSheetsAPI.git
cd SpreadSheetsAPI
```
npm install
Create a .env
file in the root of your project:
MONGODB_URL=your_mongodb_url
BRIDGING_SPREADSHEET_ID=your_bridging_spreadsheet_id
BRIDGING_BPJS_SPREADSHEET_ID=your_bridging_bpjs_spreadsheet_id
BRIDGING_SATU_SEHAT_SPREADSHEET_ID=your_bridging_satu_sehat_spreadsheet_id
DATABASES_HOSTS=http://localhost:3001,http://localhost:3002,http://localhost:3003
- Create a Google Cloud project.
- Go to the API and Services section and enable the Google Sheets API and Google Drive API.
- Create Service Account credentials, download the JSON file, and place it in the root directory as
service-account-key.json
. - Share the Google Sheet with the service account email (found in the JSON file).
- If using MongoDB Atlas, create a cluster and get the connection string.
- For local MongoDB, ensure it is running.
npm start
Navigate to http://localhost:3000
to log in with Google.
Navigate to http://localhost:3000/update-spreadsheet
to update Google Sheets with data.
Logs are stored in local files and MongoDB:
error.log
: Error level logscombined.log
: All logs- MongoDB: Logs stored in the
log
collection
project-root/
├── config/
│ └── google.config.ts
├── controllers/
│ └── google-sheets.controller.ts
├── services/
│ └── google-sheets.service.ts
├── util/
│ └── logger.ts
├── .env
├── package.json
├── README.md
└── tsconfig.json