This little program will display a random image from a folder specified.
note: This guide is for Linux/Mac and assumes you have docker installed. If you're running Windows, use WSL.
- Check out
app/server.js
, this is where the magic happens. - Under the
Local Constants
section, change theimageFolder
to the folder you want to display images from and theport
to whatever port you want to use. - Put the images you want to display in the folder you specified.
- Run
chmod +x
on thebuildandrun.sh
file. - Run
./buildandrun.sh
in the terminal. Which will start the server. - Open your browser and go to
http://localhost:port
whereport
is the port you specified in theLocal Constants
section. - Refresh the page to see a new image.
- Enjoy!
- I wanted to make a simple program that I could use to display random images for my wildcard subdomains.
- I wanted to learn a little more Node.js and how to use it to create a simple server.
- I was going to use Python/FastAPI (which I'm more familiar with) but I would have had to write a front-end in JS anyway.
- It literally just took me a few minutes to make.
- I'm Daniel Morley, a Backend Python Developer from Melbourne, Australia. I enjoy tinkering with my home server and sometimes write small projects like this (and sometimes some larger).
- Sure! Feel free to modify it and share it with the world.
- sigh yes, as long as you don't break anything Random Image @ Morley's Exact Club
- Maybe, but this wasn't the original idea. I was hoping to return a full 404 page with a random image and styling etc. Maybe I'll end up doing that and changing this project to something written in react.js, maybe I'll just leave it as is ¯\_(ツ)_/¯