Skip to content

Instantly share code, notes, and snippets.

@CAYdenberg
Created February 25, 2017 17:30
Show Gist options
  • Save CAYdenberg/b8426f2119ddd45e796372ce32ab13ee to your computer and use it in GitHub Desktop.
Save CAYdenberg/b8426f2119ddd45e796372ce32ab13ee to your computer and use it in GitHub Desktop.
Web task demo - countdown api
"use latest"
const moment = require("moment");
/* When used with Webtask (https://webtask.io)
creates a simple API that returns the number of days between now
and the given `date`.
e.g. https://address.run.webtask.io/index?date=20180225
will return: 364
when run on Feb 25th, 2017 (one year earlier) */
module.exports = (ctx, done) => {
const date = moment(ctx.data.date, 'YYYYMMDD');
done(null, date.diff(moment(), 'days'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment