Cookbook · Node.js 18+
Weekly menu with cost
On Saturday morning, the menu for seven evenings: recipes under your budget per serving, with their time and today's cost, plus one shopping list where the same ingredients add up.
- Runs on
- Node.js 18+
- One run
- 9 credits
- A month
- 45 credits
- Set up in
- 5 min
$ MAX_PER_SERVING=20 TAGS=traditional node weekly_menu.mjsmenu-2026-11-21.md: 7 dinners from 7 recipes, 412.30 lei, 9 creditsHow it works
- Get the recipes with today's cost from
/v1/recipes, worked out from shop prices. - Keep the recipes of up to
MAX_PER_SERVINGlei per serving with the tags inTAGS, the cheapest first. - For each recipe picked, read its ingredients from
/v1/recipes/{slug}. - Add up the same ingredients into one list and write
menu-YYYY-MM-DD.md, with the week's cost.
What it costs: 2 credits for the list, 1 for each recipe: 9 credits a week. Once a week: at most 45 credits a month. Fits in the Start plan.
How to run it
export SATELIT_KEY=sat_live_...
MAX_PER_SERVING=20 TAGS=traditional node weekly_menu.mjsWhat it outputs
menu-2026-11-21.md: 7 dinners from 7 recipes, 412.30 lei, 9 creditsThe full script
#!/usr/bin/env node
// Weekly menu with today's cost: seven dinners under a budget per serving and one shopping list.
// SATELIT_KEY=sat_live_... node weekly_menu.mjs
// Optional: DAYS (7), MAX_PER_SERVING (lei, 25), TAGS (vegetarian, traditional... all must match), MENU_LANG (ro).
// Writes menu-YYYY-MM-DD.md. No dependencies, Node 18 or newer. Put it in cron: 0 10 * * 6 node /path/weekly_menu.mjs
import { writeFileSync } from "node:fs";
const BASE = process.env.SATELIT_BASE ?? "https://api.satelit.md/v1";
const KEY = process.env.SATELIT_KEY;
const LANG = process.env.MENU_LANG ?? "ro";
const DAYS = Number(process.env.DAYS ?? 7);
const MAX = Number(process.env.MAX_PER_SERVING ?? 25);
const TAGS = (process.env.TAGS ?? "").split(",").filter(Boolean);
if (!KEY) throw new Error("Set SATELIT_KEY");
const WORDS = {
ro: { title: "Meniul săptămânii", day: "Ziua", list: "Lista de cumpărături", total: "Costul de azi", serving: "porție", min: "min" },
ru: { title: "Меню на неделю", day: "День", list: "Список покупок", total: "Стоимость сегодня", serving: "порция", min: "мин" },
en: { title: "This week's menu", day: "Day", list: "Shopping list", total: "Today's cost", serving: "serving", min: "min" },
uk: { title: "Меню на тиждень", day: "День", list: "Список покупок", total: "Вартість сьогодні", serving: "порція", min: "хв" },
};
const w = WORDS[LANG];
let credits = 0;
async function api(path, params = {}) {
const url = new URL(BASE + path);
for (const [k, v] of Object.entries({ lang: LANG, ...params })) url.searchParams.set(k, v);
for (let attempt = 0; ; attempt++) {
const res = await fetch(url, { headers: { Authorization: `Bearer ${KEY}` } });
const retry = Number(res.headers.get("retry-after"));
if ((res.status === 429 || res.status === 503) && retry && attempt < 2) {
await new Promise((ok) => setTimeout(ok, retry * 1000));
continue;
}
const body = await res.json();
if (!res.ok) throw new Error(`${path}: ${body.error.code}: ${body.error.message}`);
credits += body.meta.credits ?? 0;
return body;
}
}
// every recipe with today's cost from the shops' prices; the cheapest per serving first
const list = await api("/recipes");
const fits = list.data
.filter((r) => r.cost_per_serving != null && r.cost_per_serving <= MAX && TAGS.every((t) => r.tags.includes(t)))
.sort((a, b) => a.cost_per_serving - b.cost_per_serving)
.slice(0, DAYS);
if (!fits.length) throw new Error(`No recipe at or under ${MAX} lei per serving`);
// each chosen recipe once, in full; fewer recipes than days repeat in order
const full = [];
for (const r of fits) full.push((await api(`/recipes/${encodeURIComponent(r.slug)}`)).data);
const week = Array.from({ length: DAYS }, (_, i) => full[i % full.length]);
// one shopping list: the same ingredient in the same unit is added up
const need = new Map();
for (const r of week) for (const it of r.ingredients) {
const k = `${it.name.toLowerCase()}|${it.unit}`;
const had = need.get(k) ?? { name: it.name, unit: it.unit, qty: 0 };
had.qty += it.qty;
need.set(k, had);
}
const total = week.reduce((s, r) => s + r.cost_today, 0);
const day = new Date().toISOString().slice(0, 10);
const md = [
`# ${w.title}, ${day}`,
"",
...week.map((r, i) => `${i + 1}. **${w.day} ${i + 1}: ${r.title}**, ${r.time_min} ${w.min}, ${r.cost_per_serving.toFixed(2)} lei/${w.serving}`),
"",
`## ${w.list}`,
"",
...[...need.values()].sort((a, b) => a.name.localeCompare(b.name, LANG)).map((n) => `- ${n.name}: ${+n.qty.toFixed(2)} ${n.unit}`),
"",
`**${w.total}: ${total.toFixed(2)} lei**`,
"",
`_${list.meta.attribution}_`,
].join("\n");
writeFileSync(`menu-${day}.md`, md + "\n");
console.log(`menu-${day}.md: ${DAYS} dinners from ${full.length} recipes, ${total.toFixed(2)} lei, ${credits} credits`);
Routes used
Questions about this cookbook
How is a recipe's cost worked out?
From today's prices of its ingredients in Moldova's shops. cost_today is for the whole recipe, cost_per_serving for one serving.
Can I make a vegetarian menu?
Yes: TAGS=vegetarian keeps only recipes with that tag. Several tags, separated by commas, must all be on the recipe.
What if there are fewer recipes than days?
The recipes found repeat in order and the shopping list adds them all up. Raise MAX_PER_SERVING for more variety.