### Deploy Node.js App with worker-deployment Source: https://github.com/udx/worker-nodejs/blob/latest/src/examples/README.md Installs the worker-deployment tool globally, navigates to the example directory, copies the deployment configuration, and runs the worker. ```bash npm install -g @udx/worker-deployment cd src/examples cp simple-server/deploy.yml deploy.yml worker run ``` -------------------------------- ### Install Deployment CLI Source: https://github.com/udx/worker-nodejs/blob/latest/README.md Installs the global deployment CLI required for managing UDX worker applications. ```bash npm install -g @udx/worker-deployment ``` -------------------------------- ### Install and Configure UDX Worker Deployment CLI Source: https://context7.com/udx/worker-nodejs/llms.txt Installs the `@udx/worker-deployment` CLI globally using npm, generates a default `deploy.yml` configuration, and starts the container with the application. ```bash # Install the worker-deployment CLI npm install -g @udx/worker-deployment # Generate a default deploy.yml configuration worker config # Start the container with your application worker run ``` -------------------------------- ### Run Container Source: https://github.com/udx/worker-nodejs/blob/latest/README.md Starts the worker container based on the current configuration. ```bash worker run ``` -------------------------------- ### Build and Test UDX Worker Node.js Project Source: https://context7.com/udx/worker-nodejs/llms.txt Commands to clone the repository, build the project for local or multiple platforms, and run validation tests. Assumes a Unix-like environment with Make and Git installed. ```bash git clone https://github.com/udx/worker-nodejs.git cd worker-nodejs # Build for local platform make build # Build for multiple platforms (linux/amd64 and linux/arm64) make build MULTIPLATFORM=true # Run validation tests make test # Run a specific test make run-test TEST_SCRIPT=10_validate_environment.sh # Run container interactively for debugging make run-it ``` -------------------------------- ### Configure and Run UDX Worker Node.js Container with Environment Variables Source: https://context7.com/udx/worker-nodejs/llms.txt Demonstrates how to configure a UDX Worker Node.js container using environment variables and Docker. This example sets application port, Node.js environment, and mounts configuration and application directories. ```bash # Application settings APP_PORT=8080 # Port for your application (default: 8080) NODE_ENV=production # Node.js environment mode # Container paths APP_HOME=/usr/src/app # Application working directory # Example: Run with custom environment docker run -d --name my-app \ -e APP_PORT=3000 \ -e NODE_ENV=development \ -e DATABASE_URL="postgres://localhost:5432/mydb" \ -v $(pwd)/app:/usr/src/app \ -v $(pwd)/app/.config/worker:/home/udx/.config/worker:ro \ -p 3000:3000 \ usabilitydynamics/udx-worker-nodejs:latest ``` -------------------------------- ### Run UDX Worker Node.js Application with Docker Source: https://context7.com/udx/worker-nodejs/llms.txt Demonstrates how to run the UDX Worker Node.js container directly using Docker commands. It includes commands for starting the container with volume mounts and environment variables, checking logs, executing commands inside the container, and stopping/removing the container. ```bash # Run container with volume mounts for application and configuration docker run -d --name my-node-app \ -v $(pwd)/my-app:/usr/src/app \ -v $(pwd)/my-app/.config/worker:/home/udx/.config/worker:ro \ -p 8080:8080 \ -e NODE_ENV=production \ usabilitydynamics/udx-worker-nodejs:latest # Check container logs docker logs my-node-app # Execute commands inside the running container docker exec -it my-node-app /bin/bash # Stop and remove the container docker rm -f my-node-app ``` -------------------------------- ### Manage UDX Worker Services with CLI Source: https://context7.com/udx/worker-nodejs/llms.txt Provides commands to manage the lifecycle of services running within the UDX Worker container. Includes restarting, checking status, stopping, and starting services. ```bash # Restart a service worker service restart simple-server # Check service status worker service status simple-server # Output: ✓ simple-server RUNNING # Stop a service worker service stop simple-server # Start a service worker service start simple-server ``` -------------------------------- ### Minimal Node.js HTTP Server for UDX Worker Source: https://context7.com/udx/worker-nodejs/llms.txt A basic Node.js HTTP server example that listens on a specified port (defaulting to 8080) and responds with a JSON message. It includes periodic logging for health monitoring. ```javascript // index.js - Simple HTTP server for UDX Worker Node.js const http = require("http"); const port = process.env.APP_PORT || 8080; const server = http.createServer((req, res) => { res.writeHead(200, { "Content-Type": "application/json" }); res.end(JSON.stringify({ message: "Welcome to UDX Worker Node.js!", timestamp: new Date().toISOString(), port: port })); }); server.listen(port, () => { console.log(`[${new Date().toISOString()}] Server started on http://localhost:${port}/`); // Periodic health log for monitoring setInterval(() => { console.log(`[${new Date().toISOString()}] Server is running...`); }, 5000); }); ``` -------------------------------- ### Test Node.js Health Endpoint using cURL Source: https://context7.com/udx/worker-nodejs/llms.txt A bash command to test the `/health` endpoint of a Node.js application running within a UDX Worker container. It sends a GET request and displays the JSON output from the health check. ```bash # Test health endpoint curl http://localhost:8080/health # Output: {"status":"healthy","uptime":123.456} ``` -------------------------------- ### Generate Configuration Source: https://github.com/udx/worker-nodejs/blob/latest/README.md Creates a default deploy.yml configuration file for the application. ```bash worker config ``` -------------------------------- ### Clone and Build Repository Source: https://github.com/udx/worker-nodejs/blob/latest/README.md Clones the source code and executes the build and test suite. ```bash git clone https://github.com/udx/worker-nodejs.git cd worker-nodejs make build make test ``` -------------------------------- ### Run Node.js App with Docker Source: https://github.com/udx/worker-nodejs/blob/latest/src/examples/README.md Launches a Node.js application as a detached Docker container, mounting the application code and configuration, and exposing port 8080. ```bash docker run -d --name my-node-app \ -v $(pwd)/simple-server:/usr/src/app \ -v $(pwd)/simple-server/.config:/home/udx/.config \ -p 8080:8080 \ usabilitydynamics/udx-worker-nodejs:latest ``` -------------------------------- ### UDX Worker Node.js Application Directory Structure Source: https://context7.com/udx/worker-nodejs/llms.txt Illustrates the recommended directory structure for a Node.js application intended to work with UDX Worker Node.js. Key files include service definitions, main entry point, package.json, and deployment configuration. ```tree my-app/ ├── .config/ │ └── worker/ │ └── services.yaml # Service definitions for process manager ├── index.js # Main application entry point ├── package.json # Node.js dependencies (optional) └── deploy.yml # Deployment configuration (project root) ``` -------------------------------- ### Configure Node.js Worker Service Source: https://github.com/udx/worker-nodejs/blob/latest/src/examples/README.md Defines a Node.js service for the UDX worker, specifying the command to run and enabling auto-start and auto-restart. ```yaml kind: workerService version: udx.io/worker-v1/service services: - name: "simple-server" command: "node /usr/src/app/index.js" autostart: true autorestart: true ``` -------------------------------- ### Run Specific Test Source: https://github.com/udx/worker-nodejs/blob/latest/README.md Executes a single test script by specifying the TEST_SCRIPT variable. ```bash make run-test TEST_SCRIPT=10_validate_environment.sh ``` -------------------------------- ### Deploy UDX Worker Node.js Application with Docker Compose Source: https://context7.com/udx/worker-nodejs/llms.txt Defines a multi-container deployment for a UDX Worker Node.js application using Docker Compose. The `docker-compose.yml` file specifies the image, volumes, ports, environment variables, and restart policy. ```yaml # docker-compose.yml version: '3' services: app: image: usabilitydynamics/udx-worker-nodejs:latest volumes: - ./my-app:/usr/src/app - ./my-app/.config/worker:/home/udx/.config/worker:ro ports: - "8080:8080" environment: - NODE_ENV=production - APP_PORT=8080 restart: unless-stopped ``` -------------------------------- ### Mount Application Code Volume Source: https://github.com/udx/worker-nodejs/blob/latest/src/examples/README.md Specifies the volume mount for the application code, mapping a local directory to the container's application path. ```bash -v ./app:/usr/src/app ``` -------------------------------- ### UDX Worker Node.js Deploy Configuration (deploy.yml) Source: https://context7.com/udx/worker-nodejs/llms.txt Defines the Docker image, volume mounts, and port mappings for a UDX Worker Node.js application deployment. It specifies the image to use and how host directories should be mounted into the container. ```yaml # deploy.yml - Deployment configuration for UDX Worker Node.js kind: workerDeployConfig version: udx.io/worker-v1/deploy config: image: "usabilitydynamics/udx-worker-nodejs:latest" # Volume mounts: "host_path:container_path" or "host_path:container_path:ro" volumes: - "./my-app:/usr/src/app" - "./my-app/.config/worker:/home/udx/.config/worker:ro" # Ports to expose: "host_port:container_port" ports: - "8080:8080" ``` -------------------------------- ### Docker Compose for Node.js App Source: https://github.com/udx/worker-nodejs/blob/latest/src/examples/README.md Defines a Docker Compose service for running a Node.js application with the UDX worker image, including volume mounts and port mapping. ```yaml version: '3' services: app: image: usabilitydynamics/udx-worker-nodejs:latest volumes: - ./simple-server:/usr/src/app - ./simple-server/.config:/home/udx/.config ports: - "8080:8080" ``` -------------------------------- ### UDX Worker Node.js Service Configuration (services.yaml) Source: https://context7.com/udx/worker-nodejs/llms.txt Configures how the UDX Worker process manager runs and supervises a Node.js application. It defines service name, command to execute, autostart/autorestart policies, and environment variables. ```yaml # .config/worker/services.yaml - Service definition for process management kind: workerService version: udx.io/worker-v1/service services: - name: "my-node-app" command: "node /usr/src/app/index.js" autostart: true # Start service when container launches autorestart: true # Restart service if it crashes envs: - "APP_PORT=8080" - "NODE_ENV=production" ``` -------------------------------- ### Mount Worker Configuration Volume Source: https://github.com/udx/worker-nodejs/blob/latest/src/examples/README.md Specifies the volume mount for the worker configuration, mapping a local configuration directory to the container's configuration path. ```bash -v ./.config:/home/udx/.config ``` -------------------------------- ### Implement Health Check Endpoint in Node.js Application Source: https://context7.com/udx/worker-nodejs/llms.txt A Node.js code snippet for `index.js` that implements a basic HTTP server with a `/health` endpoint. This endpoint returns a JSON response indicating the application's status and uptime, suitable for container orchestration health checks. ```javascript // index.js with health check endpoint const http = require("http"); const port = process.env.APP_PORT || 8080; const server = http.createServer((req, res) => { if (req.url === "/health" && req.method === "GET") { res.writeHead(200, { "Content-Type": "application/json" }); res.end(JSON.stringify({ status: "healthy", uptime: process.uptime() })); return; } res.writeHead(200, { "Content-Type": "text/plain" }); res.end("UDX Worker Node.js Application"); }); server.listen(port, () => { console.log(`[${new Date().toISOString()}] Server listening on port ${port}`); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.