random-gopher container import express from ‘express’ ; import { readdir } from ‘node:fs/promises’ ; import path
from ‘node:path’ ;
let app = express(); let chosenGopher; async function initFiles() { try { const files = await readdir( ‘gophers’ ); const gophers = files.filter( (item) => item.endsWith( ‘png’) || item.endsWith( ‘jpg’) ); const randomIndex = Math.floor((Math.random()*gophers.length)); chosenGopher = gophers[randomIndex]; console.log(chosenGopher); } catch (err) { console.error(err); } }
At startup it chooses and exposes a random gopher