Node.js Google Calendar API Example to Get Holidays & Events of Country Using Date in Browser Using Javascript Full Project For Beginners

 

 

Google Calendar Helper

Use Google Calendar API v3 to

  • check if a date is holiday
  • get holiday names of a given date

with a given list of publicly available calendars

Installation

npm install --save google-calendar-holiday

Set up your credentials and Google Calendar

Enable Google Calendar API https://developers.google.com/calendar/quickstart/nodejs

Create an API key in Credentials page

 

Examples

 

 

const GoolgeCalendarHoliday = require('google-calendar-holiday');
const holiday = new GoolgeCalendarHoliday(
  'API_KEY',
  {
    hkHoliday: 'zh-tw.hong_kong%23holiday%40group.v.calendar.google.com',
    usHoliday: 'en.usa%23holiday%40group.v.calendar.google.com',
  },
);
// this will try to make an API call to test if the API key is valid
await holiday.init();

 

Check whether a date is holiday

 

 

holiday.isHoliday('2018-10-17') // true
holiday.isHoliday('2018-11-22') // true
 
// specify calendars
holiday.isHoliday('2018-10-17', ['hkHoliday']) // true
holiday.isHoliday('2018-11-22', ['hkHoliday']) // false

 

See also  Build a PDF.js Adobe Acrobat Online PDF Document Editor Clone in Browser Using FabricJS,jsPDF to Annotate & Modify PDF Document in Editor Using HTML5 & Javascript Full Project For Beginners

 

Get holiday names of a date

 

 

holiday.getHolidayNames('2018-10-17') // ['重陽節']
holiday.getHolidayNames('2018-11-22') // ['Thanksgiving Day']
holiday.getHolidayNames('2018-01-01') // ['元旦', 'New Year's Day']
 
// specify calendars
holiday.getHolidayNames('2018-10-17', ['hkHoliday']) // ['重陽節']
holiday.getHolidayNames('2018-11-22', ['hkHoliday']) // ['']

Leave a Reply