This project creates a simple Express server that fetches a random fun fact from the Useless Facts API and returns it in a clean JSON format.
/api/fun-facttext field and returns:
{
“fact”: “Some random fact…”
}npm installnode server.jshttp://localhost:3000/api/fun-factReflection Questions
Reformatting keeps the API response clean and minimal. It hides unnecessary fields from the external API and ensures the client only receives the information it actually needs. This makes your API easier to use and prevents breaking changes if the external API structure changes.
Actual axios errors may contain sensitive internal details, stack traces, or URLs. A generic message protects the server, avoids confusing the client, and keeps the API secure.
If the external API supports it, you could add a query parameter such as:
?language=de
Example:
https://uselessfacts.jsph.pl/api/v2/facts/random?language=de
You could also let the client choose a language using req.query.lang.