A simple Node.js application using Express to serve a rotating image slideshow with automatic image synchronization.
- Ensure you have Node.js installed.
- Clone this repository or download the files.
- Navigate to the project directory and run
npm installto install dependencies. - Place your images in the
public/imagesdirectory, or use the sync script to download them automatically. - Start the server with
node server.jsornpm start. - Open your browser and visit
http://localhost:3000to see the rotating images.
- Automatically rotates through images every 3 seconds.
- Dynamically loads images from the
public/imagesdirectory. - Serves static files from the
publicdirectory. - Command-line image synchronization script for automated deployments.
To run NodePromo as a system service on Ubuntu using the provided init script:
- Ensure your NodePromo application is installed in
/opt/nodepromo(or modify theAPP_DIRvariable in the init script) - Make sure Node.js is installed at
/usr/bin/node - Create the log directory:
sudo mkdir -p /var/log/nodepromo
-
Copy the init script to the system directory:
sudo cp nodepromo.init /etc/init.d/nodepromo
-
Make the script executable:
sudo chmod +x /etc/init.d/nodepromo
-
Enable the service to start at boot:
sudo update-rc.d nodepromo defaults
-
Start the service:
sudo service nodepromo start
- Start the service:
sudo service nodepromo start - Stop the service:
sudo service nodepromo stop - Restart the service:
sudo service nodepromo restart - Check service status:
sudo service nodepromo status - View logs:
sudo tail -f /var/log/nodepromo/nodepromo.log
Before installing, you may need to modify the following variables in nodepromo.init to match your environment:
APP_DIR: Directory where NodePromo is installed (default:/opt/nodepromo)APP_USER: User to run the service as (default:www-data)APP_GROUP: Group to run the service as (default:www-data)NODE: Path to Node.js executable (default:/usr/bin/node)
To remove the service:
-
Stop the service:
sudo service nodepromo stop
-
Disable the service:
sudo update-rc.d nodepromo remove
-
Remove the init script:
sudo rm /etc/init.d/nodepromo
The sync-images.js script allows you to automatically download and sync images from a remote JSON source:
node sync-images.js <json-url> [base-url]# For JSON with full URLs
node sync-images.js https://api.example.com/images.json
# For JSON with only filenames (requires base URL)
node sync-images.js https://api.example.com/promos.json https://cdn.example.com/imagesThe script supports multiple JSON formats:
- Simple array of URLs:
[
"https://example.com/image1.jpg",
"https://example.com/image2.jpg"
]- Object with images array (allows custom filenames):
{
"images": [
{
"url": "https://example.com/image1.jpg",
"filename": "custom_name1.jpg"
},
{
"url": "https://example.com/image2.jpg",
"filename": "custom_name2.jpg"
}
]
}- Object with promos array (filenames only - requires base URL):
{
"promos": [
{"file_name": "image1.jpg"},
{"file_name": "image2.webp"},
{"file_name": "image3.png"}
]
}- Fetches the JSON data from the provided URL
- Downloads any new images to
public/images/ - Removes any local images not present in the JSON list
- Provides detailed logging of all operations
- Includes retry logic for failed downloads
- Supports WebP, JPG, PNG, and GIF formats
sudo nano /etc/weston.iniAdd or modify:
[core]
debug=false
cd /opt/nodepromo && sudo -u www-data git pull
To run the sync script every 5 minutes via cron:
sudo touch /var/log/nodepromo-sync.log && sudo chown www-data:www-data /var/log/nodepromo-sync.log
# Edit crontab
sudo -u www-data crontab -e
# Add this line to run every 5 minutes
*/5 * * * * cd /opt/nodepromo && /usr/bin/node /opt/nodepromo/sync-images.js >> /var/log/nodepromo-sync.log 2>&1