Environment:APIJSON APIJSON Demo Node js
| Knowledge Sources | |
|---|---|
| Domains | Runtime, Testing, DevOps |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Node.js runtime environment required by the APIAuto test runner, managed as a supervised child process by the APIJSON Demo server for automated regression testing.
Description
This environment provides the Node.js runtime that executes the APIAuto test UI server (js/server.js). The Java-side AutoTestNodeProcessSupervisor launches and monitors the Node.js process via ProcessBuilder. The working directory defaults to src/main/resources/static/api, and the process listens on port 3000. The node_modules directory must exist (populated via npm install). The supervisor checks health every 30 seconds and restarts the process if unreachable.
Usage
Use this environment for the AutoTestNodeProcessSupervisor implementation, which manages the Node.js process lifecycle for automated API regression testing. Node.js must be installed and the node command must be on the system PATH.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux / macOS / Windows | Any OS supporting Node.js |
| Hardware | 1GB RAM minimum | Node.js test runner |
| Disk | 500MB | For Node.js, node_modules, and test artifacts |
Dependencies
System Packages
- Node.js 18+ (LTS recommended)
- npm (bundled with Node.js)
Java Packages
- None (Node.js is an external runtime invoked via ProcessBuilder)
Credentials
The following environment variables can be configured in `application.yml`:
- `AUTO_TEST_NODE_COMMAND` — Node.js executable (default: `node`)
- `AUTO_TEST_NODE_SCRIPT` — Script path (default: `js/server.js`)
- `AUTO_TEST_NODE_WORKING_DIRECTORY` — Working dir (default: `src/main/resources/static/api`)
- `AUTO_TEST_NODE_ENABLED` — Enable/disable Node supervision (default: `true`)
- `AUTO_TEST_NODE_STARTUP_TIMEOUT_MILLIS` — Startup timeout (default: `60000`)
- `AUTO_TEST_NODE_HEALTH_CHECK_INTERVAL_MILLIS` — Health check interval (default: `30000`)
Quick Install
# Install Node.js (Ubuntu/Debian)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install nodejs
node --version # Verify: v18.x.x
# Install APIAuto dependencies
cd APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api
npm install
Code Evidence
Node.js process launch from `AutoTestNodeProcessSupervisor.java:118-128`:
ProcessBuilder builder = new ProcessBuilder(nodeCommand, nodeScript);
builder.directory(workingDirectory.toFile());
builder.redirectErrorStream(true);
builder.redirectOutput(ProcessBuilder.Redirect.appendTo(logFilePath.toFile()));
process = builder.start();
Log.d(TAG, "已启动 APIAuto Node 守护进程,pid = " + process.pid());
Node.js configuration from `application.yml:120-125`:
apijson:
auto-test:
node:
enabled: ${AUTO_TEST_NODE_ENABLED:true}
command: ${AUTO_TEST_NODE_COMMAND:node}
script: ${AUTO_TEST_NODE_SCRIPT:js/server.js}
working-directory: ${AUTO_TEST_NODE_WORKING_DIRECTORY:src/main/resources/static/api}
node_modules check from `AutoTestNodeProcessSupervisor.java:112-114`:
if (!Files.isDirectory(workingDirectory.resolve("node_modules"))) {
Log.w(TAG, "Node 依赖目录不存在,若启动失败请先在 " + workingDirectory + " 下执行 npm install");
}
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `启动 Node 守护进程失败,请确认已安装 node` | Node.js not installed or not on PATH | Install Node.js or set `AUTO_TEST_NODE_COMMAND` to full path |
| `Node 启动脚本不存在` | Script path not found | Verify `js/server.js` exists in working directory |
| `Node 依赖目录不存在` | `npm install` not run | Run `npm install` in the static/api directory |
| `等待 Node 守护进程就绪超时` | Process started but port 3000 not responding | Check `logs/api-auto-node.log` for errors |
Compatibility Notes
- Node.js 18+ recommended: LTS versions provide better stability for long-running test processes.
- Working directory: If relative, it is resolved against `System.getProperty("user.dir")`. Use absolute paths for deployment.
- Port 3000: The Node.js test server defaults to port 3000. The supervisor polls `http://localhost:3000/test/status` for health checks.
- Graceful shutdown: The
@PreDestroyhook callsprocess.destroy()on JVM shutdown.