Configuring a Repl
Every Repl comes with two configuration files .replit
and replit.nix
. The .replit
file controls multiple aspects of your Repl's behavior including the run command, LSP (Language Server Protocol), whether your Repl is a Workspace Extension, and more.
This page will cover configuring the .replit
file, which follows the toml configuration format. To view this file, click on the three-dot menu on the file tree and select Show hidden files.
run
Gets executed when the Run button is clicked.
This command has lower precedence than [interpreter] > command
, meaning [interpreter] > command
will override run
.
run = "node index.js"
onBoot
The command that executes when your Repl boots up.
onBoot = "npm install"
compile
Runs directly before the run
command. Used for compiled languages like C, C++, Java, etc.
language
During a GitHub import, this tells the workspace which language should be used when creating the Repl.
language = "javascript"
entrypoint
The name of the main file including the extension. This is the file that will be run, and shown by default when opening the editor.
entrypoint = "index.js"
hidden
A list of files or folders to hide by default in the side filetree. These filepaths are still accessible through clicking the three dot menu in the file tree, and selecting Show hidden files.
hidden = [".config", "package-lock.json", "*.zip", "**/*.svg"]
audio
Enables system-wide audio for the Repl when configured to true
.
audio = true
[languages]
Specifies whether LSP (Language Server Protocol) should be enabled for the following specified languages.
[languages.<language name>]
Pre-language configuration. The language name has no special meaning other than to allow multiple languages to be configured at once.
pattern
Type: string
A glob used to identify which files belong to the specified language configuration.
[languages]
[languages.javascript]
pattern = "**/{*.js,*.jsx,*.ts,*.tsx,*.json}"
[languages.<language name>.languageServer]
Configuration for setting up LSP for the specified language. This allows for code intelligence (autocomplete, underlined errors, etc).
start
The command used to start the LSP server for the specified language.
[languages]
[languages.javascript]
pattern = "**/{*.js,*.jsx,*.ts,*.tsx,*.json}"
[languages.javascript.languageServer]
start = "typescript-language-server --stdio"
[[hints]]
Set hints to display in the console/shell alongside your output. You can have any number of hints in a Repl.
Each hint is required to consist of a regex
and a message
. The regex
is a regular expression that searches through your output. If a match is found, the message
is printed logged to the console/shell.
[[hints]]
regex = "ERROR"
message = "Something went wrong."
[[hints]]
regex = "exit status [12]"
message = "Bad exit code, an error occurred."
[nix]
Specifies the Nix channel your Repl will use.
channel
A nix channel ID.
[nix]
channel = "stable-22_11"
[[ports]]
Type: {localPort, externalPort, exposeLocalhost}
The [[ports]]
config Allows you to configure which HTTP port to expose for your web output. By default, any exposed HTTP port with host 0.0.0.0 will be exposed as your Repl's web output.
Extra ports can be served without overriding the default port by adding a new [[ports]] entry to your .replit file. You are required to specify both a localPort and externalPort entry. You can add multiple extra ports by adding multiple [[ports]] entries to your .replit file as defined below.
localPort
Determines which port Replit will bind to an external port.
externalPort
Determines which port should be exposed for that local port’s publicly accessible port.
[[ports]]
localPort = 3000
externalPort = 80
If you want to never expose a particular port, you can leave the localPort
config but just not add an externalPort
:
[[ports]]
localPort = 3000
exposeLocalhost
Determines whether an internal port using localhost
can be bound to an external port. Can be true
, false
, or null.
[[ports]]
localPort = 3000
externalPort = 80
exposeLocalhost = true
[extension]
Specifies whether a Repl is a Workspace Extension.
isExtension
Should be set to true
in an extension Repl. This makes the Extension Devtools accessible and optimizes the workspace for developing extensions.
[extension]
isExtension = true
extensionID
Determines if a Repl is attached to a specific extension. If unset, publishing your Extension creates a new extension and automatically fills extensionID
for you.
[extension]
extensionID = "492a5fcd-f090-4356-ace8-50755e8deb2b"
buildCommand
This command is run to bundle your extension into a static directory (specified by outputDirectory
below), which is then uploaded to Replit as an Extension.
[extension]
buildCommand = "npm run build"
outputDirectory
The path to the static directory that should be used to render the Extension. This path is relative to your Repl's root directory.
[extension]
outputDirectory = "./dist"
[env]
A key-value object of environment variables. For sensitive environment variables, use Secrets instead.
[env]
VIRTUAL_ENV = "/home/runner/${REPL_SLUG}/venv"
PATH = "${VIRTUAL_ENV}/bin"
PYTHONPATH="${VIRTUAL_ENV}/lib/python3.8/site-packages"
[unitTest]
If set, enables unit testing for the Repl.
language
The language for unit tests. Unit testing is only available for java
, python
, and nodejs
.
[unitTest]
langhage = "nodejs"
[interpreter]
Specifies the interpreter, which should be a compliant prybar binary.
command
Starts the interpreter. Overrides the run
command if set.
[interpreter]
command = [
"prybar-nodejs",
"-q",
"--ps1",
"\u0001\u001b[33m\u0002\u0001\u001b[00m\u0002 ",
"-i"
]
prompt
A list of bytes used to detect running state, if unspecified it defaults to [0xEE, 0xA7]
.
[interpreter]
prompt = [0xEE, 0xA7]
[packager]
If set, enables package management with the Packager .
afterInstall
If set, is executed after a new package is installed via the Packager.
[packager]
afterInstall = "echo 'package installed'"
ignoredPaths
A list of paths to ignore while attempting to guess packages.
[packager]
ignoredPaths = [".git"]
ignoredPackages
A list of modules to never attempt to guess a package for, when installing packages.
[packager]
ignoredPackages = ["twitter", "discord"]
language
Specifies the language to use for package operations. See available languages in the Universal Package Manager repository.
[packager]
language = "python"
[packager.features]
UPM features that are supported by the specified languages.
packageSearch
When set to true
, enables support for the Packager.
[packager]
language = "python3"
[packager.features]
packageSearch = true
guessImports
When set to true
, UPM will attempt to guess which packages need to be installed prior to running the Repl.
[packager]
language = "python3"
[packager.features]
guessImports = true
enabledForHosting
Sets whether hosting the Repl requires running a package installation operation.
[packager]
language = "python3"
[packager.features]
enabledForHosting = false
[deployment]
run
The command that executes when a Deployment container starts.
[deployment]
run = "npm start"
build
The command that executes before running a Deployment.
[deployment]
build = "npm run build"
ignorePorts
If true
, we won't check if a Repl has opened a port in order to deem a deployment as successful.
[deployment]
ignorePorts = true
Repl environment metadata
In some cases, it's useful to retrieve some metadata about the current Repl you're in. Every Repl has some pre-populated environment variables, exposing some information about itself.
To access this data, first retrieve your Repl's environment variables by running the following commands in the shell:
Node.js
console.log(process.env);
Python
import os
print(os.environ)
Rust
use std::env;
fn main() {
for (key, value) in env::vars() {
println!("{}: {}", key, value);
}
}
You can access a single environment variable from within a Repl by running the following commands in the shell:
Node.js
const variable = process.env.REPL_SLUG;
console.log(variable);
Python
import os
variable = os.environ.get('REPL_SLUG')
print(variable)
Rust
use std::env;
fn main() {
let variable = env::var("REPL_SLUG").unwrap();
println!("{}", variable);
}
Some useful environment variables accessible from within your Repl include:
key | description |
---|---|
REPL_OWNER | The username of the owner of the Repl. If your Repl is text-based and has no webserver, REPL_OWNER will reflect the value of the current user accessing the Repl |
REPLIT_DB_URL | The URL of your key-value Replit database |
REPL_ID | The unique UUID string of your Repl |
HOME | The home path of your Repl |
system | The system name of your Repl |
LANG | Text language and encoding |
REPL_IMAGE | The docker image that corresponds to your Repl |
REPL_LANGUAGE | The language of your Repl |
REPL_PUBKEYS | A stringified JSON object containing different public api keys |
REPL_SLUG | The slug of your Repl |
PRYBAR_FILE | The main/entrypoint file of your Repl |