What is the Default Port for the FreeLLMAPI Server?

The FreeLLMAPI server listens on port 3001 by default when no PORT environment variable is provided.

The FreeLLMAPI project provides an open-source API server for interacting with large language models. Understanding the default port configuration is essential for local development and deployment scenarios. This guide explains how the server determines its listening port based on the source code in tashfeenahmed/freellmapi and how to customize it.

Where the Default Port is Defined

In server/src/index.ts, the application defines the listening port using the nullish coalescing operator:

const PORT = process.env.PORT ?? 3001;

This line checks for a PORT environment variable first. If none exists, it falls back to 3001. The server then starts with this value:

app.listen(Number(PORT), '0.0.0.0', () => {
  console.log(`Server running on http://[::]:${PORT}`);
});

How to Change the Listening Port

You can override the default port using several methods.

Using Environment Variables (Inline)

Set the PORT variable when starting the server:

PORT=8080 npm start

The console output confirms the new binding:


Server running on http://[::]:8080
Proxy endpoint: http://[::]:8080/v1/chat/completions

Using a .env File

Create a .env file in the project root following the example in .env.example:


PORT=5000

When you run npm start, the server reads this configuration and binds to port 5000.

Starting the Server

Here are the complete steps for running FreeLLMAPI with different port configurations.

With the Default Port (3001)

git clone https://github.com/tashfeenahmed/freellmapi.git
cd freellmapi
npm install
npm start

Expected output:


Server running on http://[::]:3001
Proxy endpoint: http://[::]:3001/v1/chat/completions

With a Custom Port

PORT=8080 npm start

Output:


Server running on http://[::]:8080
Proxy endpoint: http://[::]:8080/v1/chat/completions

Summary

  • Default port: 3001, defined in server/src/index.ts using process.env.PORT ?? 3001
  • Environment variable: Set PORT to override the default before starting the server
  • Configuration file: Use a .env file for persistent port configuration
  • Fallback behavior: If no environment variable is set, the server always defaults to 3001

Frequently Asked Questions

What is the default port for FreeLLMAPI?

The default port is 3001. This value is hardcoded as a fallback in server/src/index.ts when the PORT environment variable is not defined.

How do I change the port in FreeLLMAPI?

You can change the port by setting the PORT environment variable before starting the server. Either run PORT=8080 npm start inline or add PORT=8080 to your .env file.

Does FreeLLMAPI support .env files?

Yes. The repository includes a .env.example file that documents supported variables including PORT. You can create a .env file in the project root to persist configuration settings.

What happens if port 3001 is already in use?

If port 3001 is occupied, the server will fail to start with an EADDRINUSE error. You must either free the port or specify a different one using the PORT environment variable before launching the application.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →