Browse documentation

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 Hosting Node.js and choose App atau API HTTP for a process serving requests. Choose Worker yang selalu aktif for an event consumer, or Skrip Node.js sekali jalan 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

  1. Download the Node.js API archive and upload it at the root in Files. Confirm index.mjs appears there.
  2. Set MAIN_FILE ke index.mjs in Variables. This example uses Node’s built-in HTTP server, so it needs no install command.
  3. Start it, wait for Node.js API listening in Console and open the HTTPS address in Settings. A GET request to / returns the JSON below.
GET /
{"service":"node-api","status":"ok"}

The API listens on 0.0.0.0 dan 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 hubungkan branch GitHub. 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 Variabel.

Check background and finite work

Ini 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 Jalankan sekarang. Look for a successful exit and JSON containing node-report. Atur JOB_TIMEOUT_SECONDS and restart to change how long an individual run may take.