This sample project demonstrates a practical integration with Google Calendar using Node.js and the Fastify framework. The application allows you to perform basic operations such as creating, reading, updating and deleting events in Google Calendar.
Node.js: JavaScript execution environment for the backend.
Fastify: Lightweight and efficient web framework for building APIs.
Zod: Library for validating data schemas.
Date-fns: Library for manipulating dates in JavaScript.
Googleapis: Official Google library for integration with its APIs.
UUID: Library for generating unique identifiers.
Make sure you have Node.js and npm installed on your system. Run the following command to install the project's dependencies:
npm install
Before running the application, you need to configure the Google Calendar API credentials. Follow the steps below:
- Creating a Project in Google Developer Console
- Go to the Google Developer Console.
- Create a new project and give it a meaningful name.
- Enabling the Google Calendar API
- In the Developer Console, go to the "Library" section.
- Search for and select "Google Calendar API".
- Click on the "Activate" button.
- Creating API credentials
- In the Developer Console, go to the "Credentials" section.
- Click on "Create credentials" and choose "OAuth client ID".
- Configure OAuth consent and fill in the necessary details.
- Select the appropriate application type (e.g. Web Application).
- Provide the appropriate redirection URIs.
- Download the JSON credentials and save them in the credentials.json file in the project directory.
With the dependencies installed and the credentials configured, you can run the application using the following command:
npm run start:dev
The application will be available at http://localhost:3333.
Before running this project, you will need to add the following environment variables to your .env
GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET
GOOGLE_API_KEY
All the necessary variables are in .env.example
GET /google/sessions
POST /google/schedule_event
Parameter | Type | Description |
---|---|---|
summary |
string |
Required. Event title |
description |
string |
Required. A brief description of the event |
attendees |
array |
Required. An object array containing the email key |
DELETE /google/schedule_event/{id}/delete
Parameter | Type | Description |
---|---|---|
id |
string |
Required. The ID of the event to be removed |
If you have any feedback, suggestions or criticisms, please let us know at charleston.silva03@gmail.com.