Express Microservice Trigger

Creates a dynamic Express.js server that triggers workflow execution on HTTP requests

Express Microservice Trigger

AI-generated

Overview

This node creates a dynamic Express.js microservice server that listens on a specified port and exposes multiple HTTP API endpoints (services). Each endpoint can trigger the execution of an n8n workflow when it receives an HTTP request. The node supports various HTTP methods, customizable response codes and content types, output templating, and authentication options per endpoint.

Common scenarios:

  • Quickly exposing custom REST API endpoints to trigger workflows.
  • Building lightweight microservices that integrate with other systems via HTTP.
  • Health checks or status endpoints for monitoring workflows.
  • Securing API endpoints with Basic Auth or API Key authentication.

Practical example:
You configure the node to listen on port 3000 and define a /health GET endpoint that returns a JSON { "status": "ok", "requestId": "<uuid>" }. When this endpoint is called, it triggers a workflow that might perform system health diagnostics or logging.

Properties

Name Meaning
Port Preferred port number for the Express server. If the port is unavailable, the node attempts to auto-select another port.
Services A collection of HTTP services (API endpoints) exposed by the microservice. Each service has the following configurable properties:

Each service item includes:

Name Meaning
Path Route path starting with / (e.g., /health, /api/users). Must be unique per HTTP method.
HTTP Method HTTP method for the route. Options: GET, POST, PUT, PATCH, DELETE.
Success Code HTTP status code returned on successful workflow execution (e.g., 200).
Failure Code HTTP status code returned if the workflow execution fails or times out (e.g., 500).
Content Type The Content-Type header for the HTTP response (default: application/json).
Output Mapping JSON template string for the response body. Supports placeholders like {{requestId}} and other variables.
Authentication Authentication method for the route. Options: None, Basic Auth, API Key.
Username Username for Basic Auth (required if Basic Auth is selected).
Password Password for Basic Auth (required if Basic Auth is selected).
API Key Header Header name to check for API key authentication (default: X-API-Key). Required if API Key auth is selected.
API Key Value Expected API key value for authentication. Required if API Key auth is selected.

Output

The node outputs data when an HTTP request triggers a workflow execution. The main output is a JSON object containing:

  • success: Boolean indicating if the workflow was triggered and completed successfully.
  • requestId: Unique UUID for the HTTP request/workflow execution.
  • timestamp: ISO timestamp of the response.
  • workflowTriggered: Whether the workflow was triggered.
  • workflowCompleted: Whether the workflow finished successfully within timeout.
  • message: Informational message about the execution result.
  • service: Object describing the invoked service (path and method).
  • result: The actual workflow execution result data.
  • executionTime: Time taken for workflow execution in milliseconds.
  • error: Present if workflow execution failed or timed out.

If the configured content type is JSON, the response body is JSON; otherwise, the raw workflow result is sent as a string.

The node does not output binary data.

Dependencies

  • Requires the express Node.js package to create the HTTP server.
  • Uses uuid package to generate unique request IDs.
  • No external API keys are required by default, but individual services may require Basic Auth credentials or API keys as configured.
  • No special environment variables needed beyond standard n8n setup.

Troubleshooting

Common issues

  • Port conflicts: If the preferred port is already in use, the node throws an error instructing to choose a different port or stop the conflicting process.
  • Duplicate routes: Defining multiple services with the same HTTP method and path combination causes validation errors.
  • Invalid JSON in output mapping: The output mapping must be valid JSON; otherwise, the node will fail validation.
  • Missing authentication details: If Basic Auth or API Key authentication is selected, missing username/password or API key header/value will cause validation errors.
  • Workflow execution timeouts: If the triggered workflow takes longer than 30 seconds, the node responds with a failure status.

Error messages and resolutions

  • "PORT IS ALREADY IN USE": Change the port number or stop the process using that port.
  • "Unsupported HTTP method": Use one of the supported HTTP methods (GET, POST, PUT, PATCH, DELETE).
  • Validation errors listing missing or invalid fields: Review the service configuration and fix missing paths, duplicate routes, invalid JSON, or incomplete authentication info.
  • "Workflow execution failed or timeout": Check the triggered workflow for errors or optimize its execution time.

Links and References

Discussion