Skip to content

HiltonStoneDev/nodepromo

Repository files navigation

NodePromo

A simple Node.js application using Express to serve a rotating image slideshow with automatic image synchronization.

Setup

  1. Ensure you have Node.js installed.
  2. Clone this repository or download the files.
  3. Navigate to the project directory and run npm install to install dependencies.
  4. Place your images in the public/images directory, or use the sync script to download them automatically.
  5. Start the server with node server.js or npm start.
  6. Open your browser and visit http://localhost:3000 to see the rotating images.

Features

  • Automatically rotates through images every 3 seconds.
  • Dynamically loads images from the public/images directory.
  • Serves static files from the public directory.
  • Command-line image synchronization script for automated deployments.

System Service Installation (Ubuntu)

To run NodePromo as a system service on Ubuntu using the provided init script:

Prerequisites

  1. Ensure your NodePromo application is installed in /opt/nodepromo (or modify the APP_DIR variable in the init script)
  2. Make sure Node.js is installed at /usr/bin/node
  3. Create the log directory: sudo mkdir -p /var/log/nodepromo

Installation Steps

  1. Copy the init script to the system directory:

    sudo cp nodepromo.init /etc/init.d/nodepromo
  2. Make the script executable:

    sudo chmod +x /etc/init.d/nodepromo
  3. Enable the service to start at boot:

    sudo update-rc.d nodepromo defaults
  4. Start the service:

    sudo service nodepromo start

Service Management Commands

  • 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

Configuration

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)

Uninstalling the Service

To remove the service:

  1. Stop the service:

    sudo service nodepromo stop
  2. Disable the service:

    sudo update-rc.d nodepromo remove
  3. Remove the init script:

    sudo rm /etc/init.d/nodepromo

Image Synchronization

The sync-images.js script allows you to automatically download and sync images from a remote JSON source:

Usage

node sync-images.js <json-url> [base-url]

Examples

# 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/images

JSON Format

The script supports multiple JSON formats:

  1. Simple array of URLs:
[
  "https://example.com/image1.jpg",
  "https://example.com/image2.jpg"
]
  1. 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"
    }
  ]
}
  1. Object with promos array (filenames only - requires base URL):
{
  "promos": [
    {"file_name": "image1.jpg"},
    {"file_name": "image2.webp"},
    {"file_name": "image3.png"}
  ]
}

What the sync script does:

  • 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

Reduce weston logging

sudo nano /etc/weston.ini

Add or modify:

[core]
debug=false

Update Source files

cd /opt/nodepromo && sudo -u www-data git pull

Cron Setup (Production)

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors