Skip to content

Getting started ​

Install ​

sh
npm install effect-prophet effect

Effect Prophet needs Node.js 22.19 or newer and is an ES module, so use import, not require.

Your first forecast ​

Copy this into a file called forecast.ts:

ts
import { Effect } from "effect";
import { fit, predict, prophetFittingBackendLayer } from "effect-prophet";

// 1. Your history: one row per day, each with a timestamp and a value.
const history = Array.from({ length: 90 }, (_, day) => ({
  timestamp: new Date(Date.UTC(2025, 0, 1 + day)).toISOString(),
  value: 100 + day * 0.5 + 10 * Math.sin((2 * Math.PI * day) / 7),
}));

// 2. The dates you want a forecast for: the next seven days.
const nextWeek = Array.from({ length: 7 }, (_, offset) =>
  new Date(Date.UTC(2025, 0, 91 + offset)).toISOString(),
);

// 3. Describe the work: fit a model to the history, then predict.
const program = Effect.gen(function* () {
  const model = yield* fit(history);

  return yield* predict(model, nextWeek);
});

// 4. Run it. The layer plugs in the forecasting engine.
const forecast = await Effect.runPromise(program.pipe(Effect.provide(prophetFittingBackendLayer)));

for (const row of forecast) {
  console.log(new Date(row.timestamp).toISOString().slice(0, 10), row.value.toFixed(1));
}

Run it:

sh
node forecast.ts

You should see a forecast for each of the next seven days:

txt
2025-04-01 137.2
2025-04-02 145.5
2025-04-03 153.8
2025-04-04 156.2
2025-04-05 151.3
2025-04-06 143.2
2025-04-07 138.3

The numbers rise and fall through the week because the model found the weekly pattern in the history on its own.

What just happened? ​

  1. History. Each row has a timestamp and a value. Timestamps are UTC strings in the exact format that Date.prototype.toISOString() produces.
  2. Future dates. You choose which dates to forecast. They can be in the future or the past.
  3. Fit, then predict. fit learns the trend and patterns from your history. predict uses the fitted model to forecast your chosen dates.
  4. Run. Steps 1 to 3 only describe the work. Effect.runPromise runs it and gives you a normal Promise. prophetFittingBackendLayer supplies the forecasting engine that fit needs.

If steps 3 and 4 feel unfamiliar, read Effect in five minutes. It is short.

Next steps ​

Inspired by Prophet from Meta. Not affiliated with Meta.