> ## Documentation Index
> Fetch the complete documentation index at: https://help.trfyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Proxy Trfyx through Express

> Proxy Trfyx analytics through an Express server.

Use Express middleware to forward the Trfyx script and event requests through your application.

<Steps>
  <Step title="Install a proxy package">
    ```bash Terminal theme={"dark"}
    npm install express-http-proxy
    ```
  </Step>

  <Step title="Add the proxy routes">
    ```js server.js theme={"dark"}
    const express = require("express");
    const proxy = require("express-http-proxy");

    const app = express();

    app.set("trust proxy", true);

    app.use(
      "/script.js",
      proxy("https://app.trfyx.com", {
        proxyReqPathResolver: () => "/script.js",
      }),
    );

    app.use(
      "/api/events",
      proxy("https://app.trfyx.com", {
        proxyReqPathResolver: () => "/api/events",
      }),
    );
    ```

    Mount these routes before a catch-all route that would otherwise consume them.
  </Step>

  <Step title="Update your tracker">
    ```html index.html theme={"dark"}
    <script
      defer
      data-website-id="YOUR_TRFYX_PROJECT_ID"
      data-domain="yourdomain.com"
      src="/script.js"
    ></script>
    ```
  </Step>

  <Step title="Verify installation">
    Deploy the server and confirm the browser requests your own `/script.js` and `/api/events` paths. Check Trfyx for the resulting activity.

    <Warning>
      Preserve the visitor's original IP through your reverse proxy. If all locations are identical, check `X-Forwarded-For` handling or switch to <a href="/managed-proxy">Managed Proxy</a>.
    </Warning>
  </Step>
</Steps>

## Next steps

<CardGroup cols={2}>
  <Card title="Goals" icon="bullseye" href="/goals" />

  <Card title="Funnels" icon="filter" href="/funnels" />

  <Card title="Managed Proxy" icon="shield-halved" href="/managed-proxy" />

  <Card title="Troubleshooting" icon="life-ring" href="/troubleshooting" />
</CardGroup>


## Related topics

- [Proxy Trfyx through your domain](/proxy-guide.md)
- [Proxy Trfyx through Nginx](/nginx-proxy.md)
- [Proxy Trfyx through PHP](/php-proxy.md)
- [Proxy Trfyx through Flask](/flask-proxy.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.