The Devvit CLI enables you to create, upload, and manage your apps. It's the bridge between your codebase and Reddit.
:::note
We collect usage metrics when you use the Devvit CLI. For more information, see Reddit’s Developer Terms and the Reddit Privacy Policy. You can opt out at any time by running npx devvit metrics off.
:::
Bundles all SVG files in the /assets folder into a new file (src/icons.ts by default). Enabling you to import local SVG assets in your app code.
$ npx devvit create icons [output-file]-
output-filePath to the output file. Defaults to
src/icons.ts.
$ npx devvit create icons
$ npx devvit create icons "src/my-icons.ts"import { Devvit } from '@devvit/public-api';
import Icons from './my-icons.ts';
Devvit.addCustomPostType({
name: 'my-custom-post',
render: (_context) => {
return (
<blocks>
<image url={Icons['my-image.svg']} imageHeight="32px" imageWidth="32px" />
</blocks>
);
},
});
export default Devvit;Display help for devvit
$ npx devvit helpInstall an app from the Apps directory to a subreddit that you moderate. You can specify a version to install or default to @latest (the latest version).
$ npx devvit install <subreddit> [app-name]@[version]-
subredditName of the installation subreddit. The "r/" prefix is optional.
-
app-nameName of the app to install (defaults to current project).
-
versionSpecify the desired version (defaults to latest).
$ npx devvit install r/mySubreddit
$ npx devvit install mySubreddit my-app
$ npx devvit install r/mySubreddit my-app@1.2.3
$ npx devvit install r/mySubreddit @1.2.3To see a list of apps you've published
$ npx devvit list appsTo see a list of all apps currently installed on a specified subreddit.
If no subreddit is specified, you'll get a list of all apps installed by you.
$ npx devvit list installs [subreddit]-
subredditName of the subreddit to look up installations for. The "r/" prefix is optional.
$ npx devvit list installs
$ npx devvit list installs mySubreddit
$ npx devvit list installs r/mySubredditLogin to Devvit with your Reddit account in the browser.
$ npx devvit login [--copy-paste]-
--copy-pasteIf present, user will copy-paste code from the browser instead of the localhost.
Logs the current user out of Devvit.
$ npx devvit logoutStream logs for an installation within a specified subreddit. You can see 5,000 logs or up to 7 days of log events.
$ npx devvit logs <subreddit> [app-name] [-d <value>] [-j] [-s <value>] [--verbose]-
subredditThe subreddit name. The "r/" prefix is optional.
-
app-nameThe app name (defaults to working directory app).
-
-d <value>, --dateformat <value>Specify the format for rendering dates. Defaults to
MMM d HH:mm:ss(Jan 15 18:30:03). See more about format options here. -
-j, --jsonOutput JSON for each log line
-
-s <value>, --since <value>Specify how far back you want the log streaming to start. Defaults to a
0m(now) if omitted.Supported format:
ssecondsmminuteshhoursddayswweeks
For example
15s,2w1d, or30m. -
--verboseDisplays the log levels and timestamps when the logs were created.
$ npx devvit logs r/mySubreddit
$ npx devvit logs mySubreddit my-app
$ npx devvit logs mySubreddit my-app --since 15s
$ npx devvit logs mySubreddit my-app --verboseCreate a new app.
$ npx devvit new [directory-name] [--here]-
directory-nameDirectory name for your new app project. This creates a new directory for your app code. If no name is entered, you will be prompted to choose one.
-
--hereGenerate the project here and not in a subdirectory.
$ npx devvit new
$ npx devvit new tic-tac-toe
$ npx devvit new --hereInstalls your app to your test subreddit and starts a playtest session. A new version of your app is installed whenever you save changes to your app code, and logs are continuously streamed. Press ctrl+c to end the playtest session. Once ended, the latest installed version will remain unless you revert to a previous version using devvit install. For more information, see the playtest page.
$ npx devvit playtest:::warning The Correct Way
devvit playtest alone does not work with devvit web. use npm run dev instead.
:::
- subreddit Name of a test subreddit with less than 200 subscribers that you moderate. The "r/" prefix is optional.
If no subreddit is specified, the command will use the first available option from:
- DEVVIT_SUBREDDIT environment variable
- dev.subreddit field in devvit.json
- The playtest subreddit stored for your app
If none exist, a new playtest subreddit will be automatically created.
Creates a new app version, uploads it along with your source for review, and then files a publish request for you app.
$ npx devvit publish [--config <value>] [--bump major|minor|patch | --version <value>] [--copy-paste] [-v]
[--public | --withdraw]-v--verbose: Enable verbose logging--config=<value>: path to devvit config file--copy-paste: Copy-paste the auth code instead of opening a browser--public: Submit the app for review to be published publicly (as opposed to unlisted, the default)--version=<value>: Explicit version number (e.g: 1.0.1)--withdraw: Withdraw the most recent publish request for your app (if it exists and is pending)
List settings for your app. These settings exist at the global app-scope and are available to all instances of your app.
$ npx devvit settings listCreate and update settings for your app. These settings will be added at the global app-scope.
$ npx devvit settings set <my-setting>$ npx devvit settings set my-feature-flagUninstall an app from a specified subreddit.
$ npx devvit uninstall <subreddit> [app-name]-
subredditName of the subreddit. The "r/" prefix is optional. Requires moderator permissions in the subreddit.
-
app-nameName of the app (defaults to the working directory app).
$ npx devvit uninstall r/mySubreddit
$ npx devvit uninstall mySubreddit
$ npx devvit uninstall mySubreddit my-appUpdate @devvit project dependencies to the currently installed CLI's version
$ npx devvit update appUpload an app to the App directory. By default the app is private and visible only to you.
$ npx devvit upload [--bump major|minor|patch|prerelease] [--copyPaste]-
--bump <option>Type of version bump (major|minor|patch|prerelease)
-
--copyPasteCopy-paste the auth code instead of opening a browser
Get the version of the locally installed Devvit CLI.
$ npx devvit versionShows you the latest version of your app and some data about uploads. Includes an optional --json flag to get information in JSON format.
$ npx devvit view [APPSLUG[@VERSION]] [--json] [version]Display the currently logged in Reddit user.
$ npx devvit whoamiThere are currently two ways to update the Devvit CLI, depending on how you installed it.
How do I know how I installed the CLI?
```bash
npm list -g --depth=0
```
If you see a line that starts with `devvit@`, it means you have the CLI installed globally. If
not, you likely have it installed as a dev dependency in your project - you can check this by
looking for `devvit` in your project's `package.json` file under the `devDependencies` section.
(If you don't see it in either place, you may not have the CLI installed at all, in which case,
you can follow the [quickstart guide](../../quickstart) to install it.)
This is the recommended way to install the CLI, as it ensures that your project uses a specific version of the CLI, and makes it substantially easier to both update the CLI, and know what version of the CLI you're using.
To update the CLI, run the following command in your project directory:
npm install --save-dev devvit@latest(Or, if you're using a different package manager, use an equivalent command to update the devvit
package to the latest version, and save it as a development dependency. DO NOT save it as a
regular dependency - we don't need the CLI code uploaded with your app!)
If you installed the CLI globally, ideally, you should uninstall the global version and install it as a dev dependency in your project instead. To do this, inside your project, run the following commands:
npm uninstall -g devvit
npm install --save-dev devvit@latestIf you still want to keep the CLI installed globally, you can update it by running the following command:
npm install -g devvit@latestThis will update the global version of the Devvit CLI to the latest version. However, please note that this is not recommended, as it can lead to inconsistencies between the CLI version used in your project and the global version. It's best to use the CLI as a dev dependency in your project to ensure that you're always using the same version across different environments.