I'm trying to fetch events from Google Calendar. I have code to do that in a js file (googlecal.js) I have posted the function that lists the events. Now I want to write a new js file and get the list of these events from the googlecal.js file. Fairly new to JS, would appreciate a direction for this.
function listEvents(auth) {
const calendar = google.calendar({version: 'v3', auth});
calendar.events.list({
calendarId: 'primary',
timeMin: (new Date()).toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime',
}, (err, res) => {
if (err) return console.log('The API returned an error: ' + err);
const eve = res.data.items;
if (eve.length) {
//console.log('Upcoming 10 events:');
eve.map((event, i) => {
const start = event.start.dateTime || event.start.date;
//console.log(`${start} - ${event.summary}`);
var attendee = event.attendees;
});
} else {
console.log('No upcoming events found.');
}
});
}
I tried to use module.exports or exporting this function and importing in a new file. But I am not very sure how to export it and import in the other js file, which is where I am facing the problem.