openartifacts.sh / templates / node-api
Node HTTP API
A minimal JSON API on Node's built-in http module: one file, no dependencies, no install step, so a cold start is just node server.mjs and the first request after a sleep is answered in about a second. Start here when you want plain JavaScript and your own routes.
Deploy it
One call publishes it as-is and boots it. It needs no environment variables. Files you send with the call replace the template's files of the same name, and fields you send override its oa.json. It is billed like any service.
With curl
# once: an account and its token
curl -sX POST "https://openartifacts.sh/v1/signup?ref=templates"
# the template, published and booted
curl -sX POST https://openartifacts.sh/v1/publish \
-H "Authorization: Bearer $OA_TOKEN" \
-F type=service -F template=node-api -F slug=my-node-api
From an MCP client
publish_artifact {"type": "service", "template": "node-api",
"slug": "my-node-api"}
With the CLI
npx @openartifacts/cli signup --ref templates # once
npx @openartifacts/cli deploy --template node-api --slug my-node-api
# or edit first: the files, here, then a normal deploy
npx @openartifacts/cli init node-api
npx @openartifacts/cli deploy ./node-api --slug my-node-api
Then: Try curl <url>/api/hello?name=agent and curl -X POST <url>/api/echo -d '{"hello":"world"}'. Add routes in server.mjs.
Call it
curl -s <url>/ # name, Node version, routes
curl -s "<url>/api/hello?name=agent" # {"message":"Hello, agent!"}
curl -s -X POST <url>/api/echo -H 'content-type: application/json' -d '{"hello":"world"}'
curl -s <url>/api/time
Errors are JSON {"code": "...", "message": "..."} with a 4xx or 5xx status.
Environment
None needed. The platform sets PORT (the server listens on 0.0.0.0:$PORT) and OA_URL (this service's public URL). Add your own with oa env set <slug> KEY=value or PUT /v1/artifacts/<slug>/env, and read them from process.env.
Extend it
- Add a route: a
'METHOD /path'key inroutesinserver.mjs. A handler gets{url, body, req}and returns[status, payload]; thrownew HttpError(status, code, message)to refuse a request. - Add a dependency: create a
package.json, add an"install": "npm ci"(or"npm install") line tooa.json, and publish the lockfile with it. The install runs on the first boot and its result is stored, so later wakes restore it in seconds; a"build"line (for example"npm run build") runs after it and is stored with it. - Keep state in
/data, written whole (write a sibling file, then rename it); everything else in the container is rebuilt on each boot.
What it costs
Prices for small, the size this template needs (current prices on openartifacts.sh):
- Asleep: no runtime charge. The bundle is stored at $0.05 per GB-month.
- Awake: $0.03 per awake hour, billed per minute, plus $0.216 per vCPU-hour of CPU actually used. A request wakes it and it stays awake 600 seconds (
sleep_after_s) after the last one, so an occasional request costs about $0.005 plus a little CPU. - Busy all day: awake around the clock is $0.72 a day plus CPU.
Starting it needs an hour of awake time in credit ($0.03), and an account runs one service per $1 of balance.
Files
README.md2.2 kBoa.json54 Bserver.mjs3.4 kB
Every file, as JSON you can edit and publish: GET /v1/templates/node-api.