Getting started
Install
sh
npm install effect-prophet effectEffect 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.tsYou 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.3The numbers rise and fall through the week because the model found the weekly pattern in the history on its own.
What just happened?
- History. Each row has a
timestampand avalue. Timestamps are UTC strings in the exact format thatDate.prototype.toISOString()produces. - Future dates. You choose which dates to forecast. They can be in the future or the past.
- Fit, then predict.
fitlearns the trend and patterns from your history.predictuses the fitted model to forecast your chosen dates. - Run. Steps 1 to 3 only describe the work.
Effect.runPromiseruns it and gives you a normalPromise.prophetFittingBackendLayersupplies the forecasting engine thatfitneeds.
If steps 3 and 4 feel unfamiliar, read Effect in five minutes. It is short.
Next steps
- Prepare your own data
- Understand what's in a forecast
- Trace your forecasts in Jaeger or any OpenTelemetry backend
- Browse the examples