Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
I

ics

> 编程语言
Open source

iCalendar (ics) file generator for node.js

787 stars0 likes0 views
WebsiteGitHub

About

iCalendar (ics) file generator for node.js

ics

The iCalendar generator

Install

npm install -S ics

Example Usage

In node / CommonJS

  1. Create an iCalendar event:
…
  1. Write an iCalendar file:
…
  1. Create multiple iCalendar events:
…

3b) Create multiple events asynchronously (large batches):

createEventsAsync returns a Promise that resolves to { error, value } (there is no callback form). While building the calendar it yields to the event loop periodically, which helps keep huge event lists from blocking Node or the browser for too long.

javascript
const { createEventsAsync } = require('ics')

async function run () {
  const { error, value } = await createEventsAsync([
    {
      title: 'Lunch',
      start: [2018, 1, 15, 12, 15],
      duration: { minutes: 45 }
    },
    {
      title: 'Dinner',
      start: [2018, 1, 15, 12, 15],
      duration: { hours: 1, minutes: 30 }
    }
  ])

  if (error) {
    console.log(error)
    return
  }

  console.log(value)
}

run()

An empty event list and optional calendar header work the same as with createEvents:

javascript
createEventsAsync([], { calName: 'My calendar' }).then(({ error, value }) => {
  if (error) console.log(error)
  else console.log(value)
})
  1. Create iCalendar events with Audio (Mac):
…

Using ESModules & in the browser

…

API

createEvent(attributes[, callback])

Generates an iCal-compliant VCALENDAR string with one VEVENT. If a callback is not provided, returns an object having the form { error, value }, where value contains an iCal-compliant string if there are no errors. If a callback is provided, returns a Node-style callback.

attributes

Object literal containing event information. Only the start property is required.

Note all date/time fields can be the array form, or a number representing the unix timestamp in milliseconds (e.g. getTime() on a Date).

The following properties are accepted:

Property Description Example
start Required. Date and time at which the event begins. [2000, 1, 5, 10, 0] (January 5, 2000) or a number
startInputType Type of the date/time data in start:
local (default): passed data is in local time.
utc: passed data is UTC
startOutputType Format of the start date/time in the output:
utc (default): the start date will be sent in UTC format.
local: the start date will be sent as "floating" (form #1 in RFC 5545)
end Time at which event ends. Either end or duration is required, but not both. [2000, 1, 5, 13, 5] (January 5, 2000 at 1pm) or a number
endInputType Type of the date/time data in end:
local: passed data is in local time.
utc: passed data is UTC.
The default is the value of startInputType
endOutputType Format of the start date/time in the output:
utc: the start date will be sent in UTC format.
local: the start date will be sent as "floating" (form #1 in RFC 5545).
The default is the value of startOutputType
duration How long the event lasts. Object literal having form { weeks, days, hours, minutes, seconds } Either end or duration is required, but not both. { hours: 1, minutes: 45 } (1 hour and 45 minutes)
title Title of event. 'Code review'
description Description of event. 'A constructive roasting of those seeking to merge into master branch'
location Intended venue Mountain Sun Pub and Brewery
geo Geographic coordinates (lat/lon) { lat: 38.9072, lon: 77.0369 }
url URL associated with event 'http://www.mountainsunpub.com/'
status Three statuses are allowed: TENTATIVE, CONFIRMED, CANCELLED CONFIRMED
organizer Person organizing the event { name: 'Adam Gibbons', email: '[email protected]', dir: 'https://linkedin.com/in/adamgibbons', sentBy: '[email protected]' }
attendees Persons invited to the event [{ name: 'Mo', email: '[email protected]', rsvp: true }, { name: 'Bo', email: '[email protected]', dir: 'https://twitter.com/bo1234', partstat: 'ACCEPTED', role: 'REQ-PARTICIPANT' }]
categories Categories associated with the event ['hacknight', 'stout month']
alarms Alerts that can be set to trigger before, during, or after the event. The following attach properties work on Mac OS: Basso, Blow, Bottle, Frog, Funk, Glass, Hero, Morse, Ping, Pop, Purr, Sousumi, Submarine, Tink { action: 'display', description: 'Reminder', trigger: [2000, 1, 4, 18, 30] } OR { action: 'display', description: 'Reminder', trigger: { hours: 2, minutes: 30, before: true } } OR { action: 'display', description: 'Reminder', trigger: { hours: 2, minutes: 30, before: false } OR { action: 'audio', description: 'Reminder', trigger: { hours: 2, minutes: 30, before: true }, repeat: 2, attachType: 'VALUE=URI', attach: 'Glass' }
productId Product which created ics, PRODID field 'adamgibbons/ics'
uid Universal unique id for event, produced by default with nanoid. Warning: This value must be globally unique. It is recommended that it follow the RFC 822 addr-spec (i.e. localpart@domain). Including the @domain half is a good way to ensure uniqueness. 'LZfXLFzPPR4NNrgjlWDxn'
method This property defines the iCalendar object method associated with the calendar object. When used in a MIME message entity, the value of this property MUST be the same as the Content-Type "method" parameter value. If either the "METHOD" property or the Content-Type "method" parameter is specified, then the other MUST also be specified. Set to undefined to omit. PUBLISH
recurrenceRule A recurrence rule, commonly referred to as an RRULE, defines the repeat pattern or rule for to-dos, journal entries and events. If specified, RRULE can be used to compute the recurrence set (the complete set of recurrence instances in a calendar component). You can use a generator like this one. FREQ=DAILY
recurrenceId Date-time used with recurring events to identify a specific instance being updated/cancelled; serialized as RECURRENCE-ID. Provide a date-time in local time. [2000, 1, 5, 10, 0] or a number
exclusionDates Array of date-time exceptions for recurring events, to-dos, journal entries, or time zone definitions. [[2000, 1, 5, 10, 0], [2000, 2, 5, 10, 0]] OR [1694941727477, 1694945327477]
sequence For sending an update for an event (with the same uid), defines the revision sequence number. 2
busyStatus Used to specify busy status for Microsoft applications, like Outlook. See Microsoft spec. 'BUSY' OR 'FREE' OR 'TENTATIVE' OR 'OOF'
transp Used to specify event transparency (does event consume actual time of an individual). Used by Google Calendar to determine if event should change attendees availability to 'Busy' or not. 'TRANSPARENT' OR 'OPAQUE'
classification This property defines the access classification for a calendar component. See iCalender spec. 'PUBLIC' OR 'PRIVATE' OR 'CONFIDENTIAL' OR any non-standard string
created Date-time representing event's creation date. Provide a date-time in local time [2000, 1, 5, 10, 0] or a number
lastModified Date-time representing date when event was last modified. Provide a date-time in local time [2000, 1, 5, 10, 0] or a number
calName Specifies the calendar (not event) name. Used by Apple iCal and Microsoft Outlook; see Open Specification 'Example Calendar'
htmlContent Used to include HTML markup in an event's description. Standard DESCRIPTION tag should contain non-HTML version. `
This is
test
html code.
`

To create an all-day event, pass only three values (year, month, and date) to the start and end properties. The date of the end property should be the day after your all-day event. For example, in order to create an all-day event occuring on October 15, 2018:

javascript
const eventAttributes = {
  start: [2018, 10, 15],
  end: [2018, 10, 16],
  /* rest of attributes */
}

callback

Optional. Node-style callback.

javascript
function (err, value) {
  if (err) {
    // if iCal generation fails, err is an object containing the reason
    // if iCal generation succeeds, err is null
  }

  console.log(value) // iCal-compliant text string
}

createEvents(events[, headerParams, callback])

Generates an iCal-compliant VCALENDAR string with multiple VEVENTS.

headerParams may be omitted, and in this case they will be read from the first event.

If a callback is not provided, returns an object having the form { error, value }, where value is an iCal-compliant text string if error is null.

If a callback is provided, returns a Node-style callback.

events

Array of attributes objects (as described in createEvent).

callback

Optional. Node-style callback.

javascript
function (err, value) {
  if (err) {
    // if iCal generation fails, err is an object containing the reason
    // if iCal generation succeeds, err is null
  }

  console.log(value) // iCal-compliant text string
}

createEventsAsync(events[, headerAttributes])

Async variant of createEvents. Resolves to an object { error, value } where value is an iCal-compliant string when error is null. There is no callback overload.

events is an array of the same attributes objects as in createEvent. The optional headerAttributes object is merged with the first event when events is non-empty, or used alone to build the calendar header when events is empty (same behavior as createEvents).

While iterating events, the implementation yields to the event loop at intervals so very large batches are less likely to freeze the process. It also builds the output in parts and joins once at the end to reduce string concatenation overhead.

Develop

Run mocha tests and watch for changes:

bash
npm start

Run tests once and exit:

bash
npm test

Build the project, compiling all ES6 files within the src directory into vanilla JavaScript in the dist directory.

bash
npm run build

References

  • RFC 5545: Internet Calendaring and Scheduling Core Object Specification (iCalendar)
  • iCalendar Validator

Issues· 29 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptalarmcalendarcalendar-eventshacktoberfest

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言