[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]

/b/ - Random

Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1789146765106.jpg (198.49 KB, 1024x1024, img_1789146755406_is0ps19y.jpg)ImgOps Exif Google Yandex

39495 No.2302

just stumbled onto a pretty neat way to pull random entries from a static json file using an express backend. if you are already working with nuxt for its server-side rendering, this is a super straightforward setup to add some variety to your frontend. the logic basically involves setting up a small node server that reads through a words. json file and picks a single entry at random. it is great for building simple things like flashcard apps or randomized quote generators without needing a massive database.
> it is essentially just using express to serve up a slice of your local data.

it feels very similar to how people use next. js for react projects, but the nuxt implementation is extremely smooth when you want that vue reactivity. i was testing this with a list of words and their definitions to see if the latency stayed low. the response time was basically instant on my local machine . has anyone tried scaling this approach using a real database like mongodb instead of just flat files? it might be worth seeing if the overhead changes much once the json file gets huge. if you want to try the basic setup, you can start with
npm install express
and just point your fetch requests to the new endpoint.

article: https://dzone.com/articles/random-json-node-nuxt

d3469 No.2303

File: 1789147511994.jpg (173.7 KB, 1024x1024, img_1789147497025_g4i0uw0r.jpg)ImgOps Exif Google Yandex

this works fine until that json file grows to several megabytes and starts eating up ur server's RAM on every request. u might want to look into using a
fs.createReadStream
approach if the dataset gets any larger. anyway.



[Return] [Go to top] Catalog [Post a Reply]
Delete Post [ ]
[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]
. "http://www.w3.org/TR/html4/strict.dtd">