-
Notifications
You must be signed in to change notification settings - Fork 152
Creating multiple events
Adam Gibbons edited this page Nov 18, 2017
·
7 revisions
To create multiple events, create an array of events and map over it. Note - currently, the ICS does not generate unique IDs when used in this manner, so make UUIDs are already assigned to your events before they're passed to ICS.
Example:
const ics = require('ics')
const fs = require('fs')
const uuidv4 = require('uuid/v4')
const events = [
{
title: 'First event',
start: [2018, 5, 30, 6, 30],
duration: { hours: 1 },
uid: uuidv4()
},
{
title: 'Second event',
start: [2018, 6, 30, 6, 30],
duration: { minutes: 30 },
uid: uuidv4()
}
]
events.map((event) => {
ics.createEvent(event, (error, value) => {
if (error) throw error
fs.writeFile(`events/${event.uid}.ics`, value, (error) => {
if (error) throw error
})
})
})