# Testing and debugging

> Run JavaScript functions locally, call them over HTTP, execute one as a job, and validate the packaged project before publishing.

Functions run locally before they are packaged, against the same runtime and the same routing the platform uses.

## Serve and call

```bash
uip function serve
```

Starts a hot-reload server on port 7070; `--port` changes it. Every HTTP function is callable at its declared path, and the root URL lists the registered routes.

Call a served function with `curl` at its declared path:

```bash
curl -X POST http://localhost:7070/hello \
  -H "Content-Type: application/json" \
  -d '{"name":"Alice"}'
```

`serve` also takes `--runtime` to choose the runtime, `node` or `deno`.

## Run one as a job

```bash
uip function run --function process-order --input '{"orderId":"A-1"}'
```

`run` executes the function once the way the platform runs a job, then prints a `JobResult` carrying the status and the output arguments. It does not need `serve` and makes no HTTP request, so `ctx.params` and `ctx.headers` are empty — the same conditions a deployed job function sees. Use it to test a function that declares no `method` and `path`.

Pass `--entrypoint` instead of `--function` to point at a file directly. One of the two is required.

## Reaching Orchestrator locally

`ctx.robot` is `null` in a local run, and `ctx.platform` is built from environment variables. Put them in a `.env` file at the project root:

```
UIPATH_ACCESS_TOKEN=<your-access-token>
UIPATH_BASE_URL=https://cloud.uipath.com
UIPATH_ORG_ID=<org id>
UIPATH_TENANT_ID=<tenant id>
```

`serve` loads that file automatically on both supported runtimes. Exporting the variables in your shell works too.

## Validating the packaged project

`serve --production` and `run --production` reproduce a platform cold start: no hot reload, and the installed server runner is reused rather than rebuilt. Running the packed output this way surfaces the failures the platform would hit on deployment — most often a runtime dependency that was left in `devDependencies`. See the [CLI reference](https://uipath.github.io/uipath-typescript/js-functions/cli-reference/) for the full recipe.

## Next steps

- [Packaging and publishing](packaging-and-publishing.md)
- [Invoking functions](invoking-functions.md)
