# What Is the Default Port for the FreeLLMAPI Proxy Server?

> Discover the default port for the FreeLLMAPI proxy server. Learn how to configure it and ensure smooth API communication. Get the essential details now.

- Repository: [Tashfeen/freellmapi](https://github.com/tashfeenahmed/freellmapi)
- Tags: faq
- Published: 2026-06-27

---

**The FreeLLMAPI proxy server listens on port 3001 by default when no `PORT` environment variable is configured.**

The default port for the FreeLLMAPI proxy server is hardcoded to **3001** across the `tashfeenahmed/freellmapi` repository. This fallback ensures the Express.js server starts successfully in development, Docker containers, and production environments without requiring manual configuration. Understanding this default behavior helps you avoid port conflicts and configure reverse proxies correctly.

## Where the Default Port Is Defined

### Runtime Configuration (server/src/lib/config.ts)

The application reads the port from `process.env.PORT` and falls back to **3001** when the environment variable is absent. This logic is implemented in [`server/src/lib/config.ts`](https://github.com/tashfeenahmed/freellmapi/blob/main/server/src/lib/config.ts), where the configuration object parses environment variables and supplies sensible defaults for the server instance.

### Docker Image Configuration (Dockerfile)

The container image explicitly declares `ENV PORT=3001` in the `Dockerfile` at the repository root. This setting ensures that containerized deployments automatically expose the service on port 3001 unless the variable is overridden at runtime.

### Environment Template (.env.example)

The repository provides a `.env.example` file that documents `PORT=3001` as the standard default. This template serves as the reference for environment-specific overrides while maintaining 3001 as the baseline value.

## How the Server Initializes the Port

In [`server/src/index.ts`](https://github.com/tashfeenahmed/freellmapi/blob/main/server/src/index.ts), the application imports the configuration and starts the Express server using the resolved port value:

```typescript
// server/src/index.ts
const { port: PORT, host: HOST } = config;
const server = app.listen(Number(PORT), HOST, onReady(HOST));
console.log(`Server running on http://${display}:${PORT}`);

```

The `Number(PORT)` cast ensures the port is passed as a numeric value to the underlying Node.js HTTP server, and the listening address is logged immediately upon successful binding.

## Overriding the Default Port

While 3001 is the built-in fallback, you can specify custom ports using environment variables or Docker Compose mappings.

### Local Development Override

Export a custom port before starting the server:

```bash
export PORT=8080
npm run start

```

The server now listens on `http://127.0.0.1:8080` instead of the default 3001.

### Docker Compose Configuration

Map a custom host port to the container's internal port:

```yaml

# docker-compose.yml

services:
  freellmapi:
    environment:
      - PORT=3001
    ports:
      - "8080:3001"

```

This exposes the proxy at `http://localhost:8080` while the container continues to use port 3001 internally.

## Summary

- The FreeLLMAPI proxy server defaults to **port 3001** when no `PORT` environment variable is set.
- The fallback is defined in [`server/src/lib/config.ts`](https://github.com/tashfeenahmed/freellmapi/blob/main/server/src/lib/config.ts) and reinforced in the `Dockerfile` and `.env.example`.
- The server initialization in [`server/src/index.ts`](https://github.com/tashfeenahmed/freellmapi/blob/main/server/src/index.ts) binds to the configured port using `app.listen(Number(PORT), HOST, ...)`.
- You can override the default by setting the `PORT` environment variable or using Docker port mappings.

## Frequently Asked Questions

### What happens if port 3001 is already in use?

If port 3001 is occupied, the Node.js process will throw an `EADDRINUSE` error and exit immediately. You must either free the port or set `PORT` to an available alternative (e.g., `PORT=3002 npm run start`) before launching the server.

### Can I run FreeLLMAPI on port 80 or 443?

Yes, but binding to ports below 1024 requires elevated privileges (root access) on most Unix systems. The recommended approach is to deploy behind a reverse proxy like Nginx that forwards traffic from ports 80/443 to the FreeLLMAPI container on port 3001.

### Does the default port change between development and production?

No, the default remains 3001 in both environments according to the source code. The [`config.ts`](https://github.com/tashfeenahmed/freellmapi/blob/main/config.ts) file uses the same fallback logic regardless of `NODE_ENV`. Production deployments typically override this via environment variables or orchestration configs (Kubernetes, Docker Compose) to align with infrastructure requirements.

### Where is the port logged when the server starts?

The listening address is logged to stdout in [`server/src/index.ts`](https://github.com/tashfeenahmed/freellmapi/blob/main/server/src/index.ts) via `console.log(\`Server running on http://${display}:${PORT}\`)`. This confirmation appears immediately after the Express server successfully binds to the configured port.