A small Next.js app that showcases a meals directory with images, summaries, and full instructions. It uses a local SQLite database (meals.db) and includes a simple seeding script to populate example meals.
- Next.js 14 app using the App Router convention (files under
app/). - A small SQLite database accessed with
better-sqlite3(meals.db). - Utility library code in
lib/for reading and writing meals. - Seed script
initdb.jsto create themealstable and insert example meals. - Public images in
public/images/and example assets inassets/.
- List and view individual meal pages (by slug).
- Create/save new meals from a form (server-side image file handling in
lib/meals.js). - Input sanitization for instructions using the
xsspackage and slug generation viaslugify.
- Node.js (recommend Node 18+).
- npm (or yarn/pnpm) for installing dependencies.
- On Windows, installing
better-sqlite3may require build tools (Visual Studio Build Tools). If you hit install errors for native modules, see the package's docs or install the platform build tools.
Open a terminal in the project folder and run:
npm installThis will install the dependencies listed in package.json (Next.js, React, better-sqlite3, slugify, xss, etc.).
The project ships with an initdb.js script that will create the meals table (if missing) and insert sample meals into meals.db.
Run it once before starting the app (or when you want to reset the seed data):
node initdb.jsAfter running that, a file named meals.db will be created/updated in the project root and populated with sample rows.
Start the Next.js dev server:
npm run devOpen http://localhost:3000 in your browser to view the app.
Available npm scripts (from package.json):
npm run dev— start dev servernpm run build— build for productionnpm run start— start built appnpm run lint— run ESLint
lib/meals.jscontains helper functions used by the app:getMeals()— returns all meals (note: the function includes an artificial 2s delay to simulate loading).getMealbySlug(slug)— returns a single meal row by slug.saveMeal(meal)— saves a new meal to the DB. It:- Generates a URL-friendly slug using
slugify. - Sanitizes
instructionsusingxss. - Stores an uploaded image to
public/images/and updates theimagepath saved in the DB.
- Generates a URL-friendly slug using
If you need to change where images are stored or how filenames are generated, update saveMeal in lib/meals.js.
app/— Next.js app pages and layout. Look here for routing and UI components.components/— React components used across the app (header, meal grid, form helpers, etc.).lib/— server-side helper functions that interact withmeals.db.initdb.js— seed script for the DB.meals.db— the SQLite database file (created byinitdb.js).public/images/— directory where meal images are served from.
Edit initdb.js to add, remove, or modify the dummyMeals array. Re-run node initdb.js to recreate/append entries. Note: the slug field is UNIQUE in the DB schema.
- If
better-sqlite3fails to install on Windows, ensure you have Visual Studio Build Tools and a compatible Python runtime installed, or consult thebetter-sqlite3GitHub page for prebuilt binaries and platform-specific steps. - If the app cannot read
meals.db, confirminitdb.jswas run and that the file exists in the project root and the process has permission to read it. - If uploaded images are not showing, check that
public/images/contains the files and that the URL paths saved in the DB (e.g./images/<slug>.<ext>) match those files.
Small, focused changes are welcome. Typical workflow:
- Fork/branch.
- Run
npm installandnode initdb.jsto get the DB seeded. - Make changes and ensure the dev server runs:
npm run dev. - Add tests or manual verification steps for UI changes.
This project template doesn't include a license file. Add one if you plan to publish or share the repository.