Configure a Replit App
Learn how to configure your Replit App using .replit and replit.nix files to manage dependencies, run commands, environment variables, and deployment settings.
Replit App are configured with two files: the .replit
and replit.nix
. They affect how your Replit App behaves, from code execution to development tools and languages.
These configuration files are hidden by default. Show them in your Replit App by selecting “Show hidden files” from the filetree menu.
replit.nix
file
Replit uses Nix
to manage packages and environments. The replit.nix
file is used for:
Specifying system dependencies: Define exactly what software packages your Replit App requires, managed through Nix, a package manager.
Creating reproducible environments: Ensure your development environment is consistent and reproducible, ideal for collaborative projects and testing across multiple systems.
You can manage Nix packages visually through the Dependencies
tool. Learn more in the System Dependencies guide.
To configure packages with the replit.nix
file, you can list Nix packages in the deps
array, prefixed with pkgs.
. Any changes will be synced after your shell is reloaded.
.replit
file
The .replit
file controls your Replit App’s behavior. It uses the toml
configuration format. Here are some of the key aspects that can be configured:
Run command: Specify the command that executes when the Run button is selected, allowing for immediate and repeated testing or execution of your code.
Language Server Protocol (LSP): Provides features like auto-complete, code navigation, code highlighting, and real-time linting and errors.
Environment variables: Set and manage environment variables essential for your applications to run correctly.
Dependencies and packages: Manage package installations and configurations directly through the .replit
file, ensuring your Replit App has all the necessary tools ready upon startup. You can manage dependencies visually through the Dependencies
tool. Learn more in the System Modules guide.
For Python applications, the default .replit
file looks like:
The following table provides a view of each setting within the .replit
file, explaining what each configuration does and its impact on the Replit App environment.
Configuration key | Value/Example | Description |
---|---|---|
entrypoint | main.py | Specifies the main file to be executed and displayed by default when the editor is opened. You can rename the file name based on your application. |
modules | ["python-3.10:v18-20230807-322e88b"] | Defines specific versions of programming languages or other major dependencies supported by Replit. |
[nix] | Specifies settings for using Nix, a package manager, to manage system dependencies. Refer to Dependency Management document for more information. | |
channel | stable-23_05 | Indicates the Nix channel to use, which affects the versions of system dependencies available. |
[unitTest] | Configures settings related to unit testing within the Replit App. | |
language | python3 | Specifies the language used for unit testing, indicating that Python 3 is used for writing tests. |
[gitHubImport] | Settings that affect how projects are imported from GitHub, specifically which files must be included. | |
requiredFiles | [".replit", "replit.nix"] | Lists the files that must be present when importing the project to ensure it functions correctly. |
[deployment] | Contains settings for deploying the application from the Replit App to a live environment. | |
run | ["python3", "main.py"] | Command executed to start the application during deployment. |
deploymentTarget | cloudrun | Specifies the deployment target platform for hosting the application. |
Now that you have an idea of the default configurations of the .replit
file use the next sections to understand how to configure basic and advanced settings for your Replit App.
Configuring basic settings
Entrypoint
This is the main file of your project. If you do not define a run
property, entrypoint
is the file that gets executed by the runtime.
Run
command
The run
property in the .replit
file is a key feature that determines the initial command or series of commands executed when the Run
button is selected in a Replit environment. The Run
command can be specified either as a string representing the command to execute, or an array of strings representing the command and individual arguments to that command.
Some common ways to configure the Run
command:
-
Single command: This example shows how to pass single command to execute directly in the Replit App. With this in your
.replit
file, pressing theRun
button will display a greeting in theConsole
pane: Example:run = "echo 'Hello, Replit!'"
-
Explicit arguments: In some situations it may be beneficial to be more explicit, avoiding the need for parsing quotes or shell interpolation rules. We can rewrite the above example to separate the arguments. Note, we no longer need both
'
and"
, since we are explicitly passing the greeting as the first and only argument toecho
: Example:run = ["echo", "Hello, Replit!"]
-
Multiple commands: This example shows how to run multiple processes, such as a frontend and a backend, simultaneously. This could be useful if developing a python backend and a typescript frontend, where each server binds to a different port: Example:
run = "python -m app & npm run start & wait"
Process management
While multiple commands can be simultaneously run with &
, you may want a better experience distinguishing logs between services. You can add system dependencies like process-compose
to better orchestrate multiple processes.
Build
phase
For some languages or runtimes, there is a separate compilation phase before code can be run
. This covers both compiled languages like TypeScript, Golang, or Java, or offering a parameter you can use to reset your environment, data, or configuration before the next run
is invoked.
- Compiling:
In a TypeScript repository, you may find yourself needing to run
tsc
prior to executing your code. Example:
Including environment variables
To supply environment variables to your service before execution, you can expand the run
property into a table.
This is a more involved change, and likely requires moving where your run = "..."
property is located inside your .replit
file.
The following diff shows suppying the command by way of [run]
’s args
, as well as the variable NAME
supplied in [run.env]
:
Interactivity
Interactive programs can also be launched by way of the Run
button, offering a way to distinguish your development environment from the terminal where your program is running.
Consider the following tally script:
Example
Advanced configuration options
Explore the detailed configuration options available for your Replit App. You can customize your development environment, manage run commands, integrate language services, and handle dependencies.
Notes about System-Wide Audio
When setting audio = true
in your .replit
file, you may need to run kill 1
in a shell to force the new setting to take effect.
When running a graphical application, you will see a pair of headphones with a checkbox in the lower right of the Output
pane.
Due to browser restrictions, this will need to be enabled every time you refresh.
Packager configuration
Example .replit
configuration for packager configuration
Deployment configuration
Example .replit
configuration for deployment configuration
Interpreter configuration has been deprecated and is no longer available in Replit. Instead, you are encouraged to use the Run
commands to configure how scripts and applications are executed within your Replit App environment.
Networking and extensions
Example .replit
configuration file for managing networking and extensions
Accessing Replit App environment metadata
Node.js
To access all environment variables:
console.log(process.env);
To access a single variable (REPL_SLUG):
console.log(process.env.REPL_SLUG);
Python
To access all environment variables:
To access a single variable (REPL_SLUG):
Rust
To access all environment variables:
To access a single variable (REPL_SLUG):
Environment variables
Following are the environment variables accessible from within your Replit App:
Was this page helpful?