# 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 process-order --input '{"orderId":"A-1"}'
```

`run` runs the function once, the way the platform runs a job, and prints a `JobResult` with the status and the output arguments. It doesn't need `serve`. `ctx.params` and `ctx.headers` are empty, as in a deployed job. Use `run` to test job functions, and `serve` to test HTTP functions. Pass `--input-file` to read the input from a JSON file.

## 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://<automation-suite-fqdn>
UIPATH_ORG_ID=<org id>
UIPATH_TENANT_ID=<tenant id>
```

`serve` loads that file. Exporting the variables in your shell works too.

## Running in production mode

`serve --production` and `run --production` start the project the way the platform does, without hot reload. See the [CLI reference](https://uipath.github.io/uipath-typescript/js-functions/cli-reference/) for details.

## Next steps

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