Skip to content

The plinth Command ​

Introduction ​

plinth is the command line tool for Plinth applications. It comes from the @plinthjs/cli package. You use it to run your application's console commands (migrations, generators, route listing), to create new applications, and to check what a project is using.

A generated application already depends on it, so inside a project you can run it straight away:

bash
npx plinth list
npx plinth migrate
npx plinth make:controller PostController --resource

With pnpm you can leave out npx: pnpm plinth migrate. The generated package.json also has a plinth script, so npm run plinth -- migrate works too.

Installing it ​

The scaffold adds @plinthjs/cli to devDependencies and tsx to dependencies. To add it to an existing project:

bash
pnpm add -D @plinthjs/cli tsx

To use plinth from any folder, including to create new applications, install it globally:

bash
npm install -g @plinthjs/cli
plinth new blog

Requirements ​

  • Node.js 22 or newer. Application commands start with node --import tsx.
  • The project's dependencies must be installed. plinth itself only finds the project and launches it. The project's own node_modules, including tsx, are used, not global ones. A freshly cloned project needs pnpm install first.
  • npm on your PATH for plinth new. It runs npm exec create-plinthjs-app@latest, so it always uses the newest scaffolder, and needs network access to the registry. On Windows it starts npm.cmd through a shell.

Commands ​

CommandWhat it does
plinth new [name]Creates an application, asking what it needs to know. Takes the same flags as create-plinthjs-app.
plinth aboutShows the project, Node version, console entry and @plinthjs/* packages.
plinth helpPrints the built-in help. Also -h and --help.
plinth --versionPrints the CLI version. Also -v.
plinthInside a project, the same as plinth list. Outside one, prints help.
plinth <anything else>Handed to the application's console. See below.
bash
plinth new                      # asks for the name and every choice
plinth new blog                 # asks the rest
plinth new blog --react --mysql # asks only what is left
plinth about

plinth new is interactive in a terminal: it asks for the project name, the starter, the frontend, the database, whether to initialise git and install dependencies, which package manager to use, and whether to run the migrations. See Installation for each question and the flags that answer them ahead of time.

plinth about prints something like this:

Plinth CLI   0.1.4
Node         v24.18.0
Project      blog
Root         /home/you/blog
Console      /home/you/blog/src/console.ts
tsx          installed
Packages
  @plinthjs/auth  ^0.1.1
  @plinthjs/cli  ^0.1.1
  ...

How application commands run ​

Every command that is not built in goes to your application's console entry, with the rest of the arguments unchanged. The command runs in the project root and its exit code is passed back, so plinth works in scripts and CI:

bash
plinth migrate --seed
echo $?   # the exit code of the migrate command

The commands themselves, such as migrate and make:controller, are defined in your application's src/routes/console.ts and the packages it registers. See Console for writing your own.

How it finds your project ​

plinth starts in the current folder and walks upward until it finds a package.json that sits next to a console entry. It looks for these files, in this order:

  1. src/console.ts
  2. src/console.mts
  3. src/console.js
  4. src/console.mjs
  5. console.ts
  6. console.js

That means you can run plinth from any subfolder of the project. Outside a project, a command other than the built-in ones fails with a message and a hint to run plinth new <name>.

TypeScript and tsx ​

Applications are written in TypeScript, and their source imports files with .js specifiers that point at .ts files. Node cannot resolve that on its own, so plinth runs a TypeScript entry through tsx, which must be installed in the project. If it is missing, the command stops and tells you to install it:

bash
npm install --save-dev tsx

A JavaScript entry (src/console.js, for example after a build step) runs directly on Node and needs no tsx.

Using it from code ​

The package also exports its pieces, which is useful for tests and tooling:

ts
import { findProject, chooseRunner } from '@plinthjs/cli'

const project = findProject(process.cwd())
// => { root: '/home/you/blog', entry: '/home/you/blog/src/console.ts' }, or null

if (project !== null) {
  chooseRunner(project.root, project.entry)
  // => { kind: 'tsx', args: ['--import', 'tsx', '/home/you/blog/src/console.ts'] }
}

runCli(argv, context) runs the whole tool with an injected environment (working folder, output, process spawner), so you can test a command line without starting any process.

Released under the MIT License.