Deploy a Node.js API, worker or one-off script
Start a Node.js project with the correct entry file, check the example API over HTTPS, and run a finite script from the Runs page.
Match the profile to the process
Open Node.js hosting and choose HTTP app or API for a process serving requests. Choose Always-on worker for an event consumer, or One-off Node.js script for a command that produces a result and exits. The examples below are independent projects. Put each in the matching deployment.
Serve the example API
- Download the Node.js API archive and upload it at the root in Files. Confirm
index.mjsappears there. - Set
MAIN_FILEtoindex.mjsin Variables. This example uses Node’s built-in HTTP server, so it needs no install command. - Start it, wait for
Node.js API listeningin Console and open the HTTPS address in Settings. A GET request to/returns the JSON below.
{"service":"node-api","status":"ok"}The API listens on 0.0.0.0 and SERVER_PORT. If your own app starts but the URL fails, follow diagnosing an unreachable Node.js API.
Deploy your own package
Upload your entry file, package manifest and lockfile, or connect a GitHub branch. In Files, check that the project root contains the package used by your start command. A wrapper directory from an archive can move the actual package one level down.
Set MAIN_FILE when you start a single file. Set RUN_COMMAND when your package controls startup. A custom command handles its own dependencies and build steps. For an npm project with a lockfile and a start script, npm ci && npm start installs before starting. Add a build step only if your project defines one. Store private API keys in Variables.
Check background and finite work
The worker example runs index.js and prints a timestamped heartbeat once a minute. Start it, watch two heartbeats in Console, then restart and look for a new first timestamp.
For the one-off example, select the job profile and use index.js. Start the deployment to bring up its runner. Open Runs and select Run now. Look for a successful exit and JSON containing node-report. Set JOB_TIMEOUT_SECONDS and restart to change how long an individual run may take.