Overview
This node creates a dynamic Express.js server that listens on a specified port and supports multiple configurable HTTP routes. Each route can be customized with its path, HTTP method, success and failure status codes, content type, response body template, and authentication method. It is useful for quickly setting up microservices or mock APIs for testing, development, or integration purposes.
Use Case Examples
- Creating a health check endpoint at /health that returns a JSON status message.
- Setting up a POST /api/users route that requires API key authentication and returns a custom response.
- Defining multiple routes with different HTTP methods and authentication schemes on the same Express server.
Properties
| Name | Meaning |
|---|---|
| Port | Port number for the Express server to listen on. |
| Methods | Collection of route definitions, each specifying the route path, HTTP method, success and failure codes, content type, response template, and authentication details. |
Output
JSON
success- Indicates if the Express server started successfully.port- Port number the server is listening on.routes- Array of strings describing each configured route with HTTP method and path.message- Informational message confirming the server start.
Dependencies
- express
- get-port
Troubleshooting
- Port already in use error: The specified port is occupied by another process. Choose a different port or stop the conflicting service.
- Invalid route path error: Route paths must start with a '/'.
- Unsupported HTTP method error: Only GET, POST, PUT, PATCH, DELETE are supported.
- Authentication errors: Basic auth requires correct username and password; API key auth requires correct header and key value.
- Response template errors: Malformed JSON in output mapping may cause response parsing issues.
Links
- Express.js Documentation - Official documentation for the Express.js web framework used by this node.
- get-port NPM Package - Utility to find an available port, used to avoid port conflicts.