Files
shopfloor-dashboard/DEPLOYMENT_WINDOWS.md
cproudlock 81cb74cdef Improve TV display visibility and add Windows deployment guide
- Increased font sizes across dashboard for better TV readability
  - Headers: 72px (was 48px)
  - Event titles: 56px (was 38px)
  - Clock: 48px (was 36px)
  - Connection status: 28px (was 18px)
- Enhanced spacing and padding throughout
- Larger logo (160px vs 100px)
- Thicker borders for better visibility
- Added comprehensive Windows deployment documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-23 15:53:25 -04:00

13 KiB

Shopfloor Dashboard - Windows Production Deployment Guide

This guide covers deploying the Shopfloor Dashboard Node.js application to a Windows production server.

Prerequisites

  • Windows Server 2016 or later (or Windows 10/11)
  • Administrative access to the server
  • MySQL database access
  • Internet connection for downloading Node.js

1. Install Node.js on Windows

  1. Download Node.js:

    • Go to https://nodejs.org/
    • Download the LTS (Long Term Support) version for Windows
    • Choose the Windows Installer (.msi) - 64-bit
  2. Run the Installer:

    • Double-click the downloaded .msi file
    • Click "Next" through the setup wizard
    • Accept the license agreement
    • Important: Make sure "Add to PATH" is checked
    • Install with default options
    • Click "Finish" when complete
  3. Verify Installation:

    • Open Command Prompt or PowerShell
    • Run these commands:
    node --version
    npm --version
    
    • You should see version numbers (e.g., v20.x.x and 10.x.x)

Option B: Using Chocolatey (Package Manager)

If you have Chocolatey installed:

# Run PowerShell as Administrator
choco install nodejs-lts -y

# Verify
node --version
npm --version

2. Deploy the Application Files

  1. Install Git for Windows:

  2. Clone the Repository:

    cd C:\inetpub\wwwroot
    git clone http://localhost:3000/cproudlock/shopfloor-dashboard.git
    cd shopfloor-dashboard
    

Option B: Manual File Copy

  1. Create Application Directory:

    mkdir C:\inetpub\wwwroot\shopfloor-dashboard
    
  2. Copy these files from development:

    • server.js
    • package.json
    • package-lock.json
    • public\ directory (entire folder)
    • .gitignore (optional)
  3. Do NOT copy:

    • node_modules\ (will be regenerated)
    • .git\ directory
    • Any .env files with passwords

3. Install Dependencies

cd C:\inetpub\wwwroot\shopfloor-dashboard
npm install --production

This will install:

  • express
  • mysql2

4. Configure Environment Variables

Option A: Using Windows Environment Variables

  1. Open System Properties:

    • Right-click "This PC" → Properties
    • Click "Advanced system settings"
    • Click "Environment Variables"
  2. Add System Variables:

    • Click "New" under System Variables
    • Add each variable:
    Variable Name: PORT
    Variable Value: 3001
    
    Variable Name: DB_HOST
    Variable Value: localhost (or your database server IP)
    
    Variable Name: DB_PORT
    Variable Value: 3306
    
    Variable Name: DB_USER
    Variable Value: 570005354 (or your production user)
    
    Variable Name: DB_PASS
    Variable Value: your-secure-password
    
    Variable Name: DB_NAME
    Variable Value: shopdb
    
    Variable Name: NODE_ENV
    Variable Value: production
    
  3. Apply and restart Command Prompt

Option B: Using a .env File (Less Secure)

Create config.js in the project root:

module.exports = {
    port: process.env.PORT || 3001,
    db: {
        host: process.env.DB_HOST || 'localhost',
        port: process.env.DB_PORT || 3306,
        user: process.env.DB_USER || '570005354',
        password: process.env.DB_PASS || 'your-password',
        database: process.env.DB_NAME || 'shopdb'
    }
};

Security Warning: Never commit passwords to Git!


5. Test the Application

cd C:\inetpub\wwwroot\shopfloor-dashboard
node server.js

You should see:

Shopfloor Dashboard running on port 3001
Access at: http://localhost:3001

Open a browser and test:

Press Ctrl+C to stop the test.


6. Set Up as a Windows Service

To run the dashboard automatically and keep it running, you need to set it up as a Windows service.

Install PM2:

npm install -g pm2
npm install -g pm2-windows-startup

Configure PM2 Windows Service:

# Set up PM2 to run at startup
pm2-startup install

# Start the application
cd C:\inetpub\wwwroot\shopfloor-dashboard
pm2 start server.js --name shopfloor-dashboard

# Save the PM2 configuration
pm2 save

Useful PM2 Commands:

pm2 status                       # Check status
pm2 logs shopfloor-dashboard     # View logs
pm2 restart shopfloor-dashboard  # Restart app
pm2 stop shopfloor-dashboard     # Stop app
pm2 delete shopfloor-dashboard   # Remove from PM2
pm2 monit                        # Real-time monitoring

PM2 Log Locations:

C:\Users\<username>\.pm2\logs\

Option B: Using NSSM (Non-Sucking Service Manager)

Download and Install NSSM:

  1. Download from https://nssm.cc/download
  2. Extract to C:\nssm\
  3. Add to PATH or use full path

Create the Service:

# Navigate to NSSM directory
cd C:\nssm\win64

# Install service
nssm install ShopfloorDashboard "C:\Program Files\nodejs\node.exe" "C:\inetpub\wwwroot\shopfloor-dashboard\server.js"

# Set working directory
nssm set ShopfloorDashboard AppDirectory C:\inetpub\wwwroot\shopfloor-dashboard

# Set environment variables
nssm set ShopfloorDashboard AppEnvironmentExtra PORT=3001 DB_HOST=localhost DB_USER=570005354 DB_PASS=your-password DB_NAME=shopdb

# Set startup type to automatic
nssm set ShopfloorDashboard Start SERVICE_AUTO_START

# Start the service
nssm start ShopfloorDashboard

Manage the Service:

# Using NSSM
nssm stop ShopfloorDashboard
nssm start ShopfloorDashboard
nssm restart ShopfloorDashboard
nssm status ShopfloorDashboard
nssm remove ShopfloorDashboard

# Or using Windows Services
services.msc  # Opens Services window

Option C: Using Windows Task Scheduler

  1. Open Task Scheduler
  2. Create Basic Task:
    • Name: Shopfloor Dashboard
    • Trigger: At system startup
    • Action: Start a program
    • Program: C:\Program Files\nodejs\node.exe
    • Arguments: C:\inetpub\wwwroot\shopfloor-dashboard\server.js
    • Start in: C:\inetpub\wwwroot\shopfloor-dashboard
  3. Properties:
    • Run whether user is logged on or not
    • Run with highest privileges
    • Configure for: Windows Server 2016 or later

7. Configure Windows Firewall

# Run PowerShell as Administrator

# Allow port 3001
New-NetFirewallRule -DisplayName "Shopfloor Dashboard" -Direction Inbound -LocalPort 3001 -Protocol TCP -Action Allow

# Or if using IIS reverse proxy, allow port 80/443
New-NetFirewallRule -DisplayName "HTTP" -Direction Inbound -LocalPort 80 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "HTTPS" -Direction Inbound -LocalPort 443 -Protocol TCP -Action Allow

8. Set Up IIS Reverse Proxy (Optional)

If you want to use IIS as a reverse proxy to add SSL or run on port 80:

Install Required IIS Components:

# Run PowerShell as Administrator
Install-WindowsFeature -name Web-Server -IncludeManagementTools

Install URL Rewrite and ARR:

  1. Download and install:

  2. Enable ARR Proxy:

    • Open IIS Manager
    • Click server name in left panel
    • Double-click "Application Request Routing Cache"
    • Click "Server Proxy Settings" in right panel
    • Check "Enable proxy"
    • Click Apply
  3. Configure URL Rewrite:

    • In IIS Manager, select Default Web Site (or create new site)
    • Double-click "URL Rewrite"
    • Click "Add Rule(s)" → "Reverse Proxy"
    • Enter: localhost:3001
    • Click OK

Now access the dashboard at:


9. Database Configuration

Ensure MySQL is accessible:

If MySQL is on the same server:

-- Connect to MySQL
mysql -u root -p

-- Grant permissions
GRANT ALL PRIVILEGES ON shopdb.* TO '570005354'@'localhost' IDENTIFIED BY 'your-secure-password';
FLUSH PRIVILEGES;

If MySQL is on a remote server:

-- On the database server
GRANT ALL PRIVILEGES ON shopdb.* TO '570005354'@'windows-server-ip' IDENTIFIED BY 'your-secure-password';
FLUSH PRIVILEGES;

Test Database Connection:

cd C:\inetpub\wwwroot\shopfloor-dashboard
node -e "const mysql = require('mysql2'); const conn = mysql.createConnection({host:'localhost',user:'570005354',password:'your-password',database:'shopdb'}); conn.connect((err) => {if(err) console.error('Error:',err); else console.log('Connected!'); conn.end();});"

10. Monitoring and Logs

Using Event Viewer (Windows):

  1. Open Event Viewer (eventvwr.msc)
  2. Navigate to: Windows Logs → Application
  3. Look for Node.js or your service name

Using PM2:

# View real-time logs
pm2 logs shopfloor-dashboard

# View specific log files
pm2 logs shopfloor-dashboard --lines 100

# Clear logs
pm2 flush

Custom Logging:

Add to server.js for file logging:

const fs = require('fs');
const path = require('path');

// Create logs directory if it doesn't exist
const logDir = path.join(__dirname, 'logs');
if (!fs.existsSync(logDir)) {
    fs.mkdirSync(logDir);
}

// Log to file
const logFile = path.join(logDir, `app-${new Date().toISOString().split('T')[0]}.log`);
const logStream = fs.createWriteStream(logFile, { flags: 'a' });

// Override console.log
const originalLog = console.log;
console.log = function(...args) {
    const timestamp = new Date().toISOString();
    const message = `[${timestamp}] ${args.join(' ')}\n`;
    logStream.write(message);
    originalLog.apply(console, args);
};

11. Security Checklist

  • Change default database passwords
  • Use Windows environment variables (not hardcoded passwords)
  • Enable Windows Firewall with only necessary ports
  • Set up SSL certificate if exposing to internet
  • Run Node.js service under limited user account (not Administrator)
  • Keep Node.js updated regularly
  • Set up automated database backups
  • Restrict database access to application server only
  • Review Windows Event Logs regularly
  • Enable Windows Defender or antivirus

12. Updating the Application

Using Git:

cd C:\inetpub\wwwroot\shopfloor-dashboard
git pull origin main
npm install --production

# If using PM2:
pm2 restart shopfloor-dashboard

# If using NSSM:
nssm restart ShopfloorDashboard

Manual Update:

  1. Stop the service
  2. Replace changed files
  3. Run npm install --production if dependencies changed
  4. Start the service

13. Troubleshooting

Application won't start:

# Check Node.js version
node --version

# Check for errors
cd C:\inetpub\wwwroot\shopfloor-dashboard
node server.js

Can't connect to database:

# Test MySQL connection
mysql -h localhost -u 570005354 -p shopdb

# Check Windows Firewall
# Check MySQL is running: services.msc

Port already in use:

# Find what's using port 3001
netstat -ano | findstr :3001

# Kill the process (replace PID with actual number)
taskkill /PID <pid> /F

Service won't start automatically:

  • Check Windows Event Viewer for errors
  • Verify service is set to "Automatic" startup
  • Check environment variables are set correctly
  • Verify file paths are correct

Can't access from other computers:

  • Check Windows Firewall rules
  • Verify application is listening on 0.0.0.0 (not just 127.0.0.1)
  • Test with: netstat -an | findstr :3001

14. Performance Optimization

For Production:

  1. Set NODE_ENV:

    setx NODE_ENV production /M
    
  2. Increase Process Priority (if using NSSM):

    nssm set ShopfloorDashboard AppPriority ABOVE_NORMAL_PRIORITY_CLASS
    
  3. Configure PM2 Cluster Mode (multiple instances):

    pm2 start server.js -i max --name shopfloor-dashboard
    

Quick Reference

Application Paths:

Application: C:\inetpub\wwwroot\shopfloor-dashboard
Node.js: C:\Program Files\nodejs
PM2 Logs: C:\Users\<username>\.pm2\logs

URLs:

Dashboard: http://localhost:3001
API: http://localhost:3001/api/notifications
Health: http://localhost:3001/health

Common Commands:

# Start manually
node server.js

# PM2
pm2 start server.js --name shopfloor-dashboard
pm2 status
pm2 logs shopfloor-dashboard
pm2 restart shopfloor-dashboard

# NSSM
nssm start ShopfloorDashboard
nssm stop ShopfloorDashboard
nssm restart ShopfloorDashboard
nssm status ShopfloorDashboard

Support

For issues or questions:

  • Check Windows Event Viewer: eventvwr.msc
  • Check application logs: PM2 or custom logs
  • Review README.md for application details
  • Contact: IT Support - West Jefferson

Last Updated: October 2025 Version: 1.0.0