Skip to content

Installation ​

Introduction ​

There are two ways to start with Plinth. The scaffolder, create-plinthjs-app, generates a complete application with the packages already wired together. Alternatively you can add individual @plinthjs packages to a project you already have. This page covers both.

Requirements ​

Plinth runs on Node.js 22 or newer. Every package declares node >= 22 in its engines field: Node 20 reached end of life in April 2026, and the generated application uses SQLite by default through Node's built-in node:sqlite module, which needs Node 22.

You also need a package manager: npm, pnpm, yarn or bun. The scaffolder detects which one started it and, when you have several installed, asks which to install with.

Creating an application ​

The quickest way is the plinth command-line tool. Install it once:

bash
npm install -g @plinthjs/cli
plinth new

plinth new interviews you, scaffolds the project and sets it up. It always fetches the latest scaffolder, so you get current templates without updating anything. You can also run the scaffolder directly, with nothing installed globally:

bash
npm create plinthjs-app@latest
pnpm create plinthjs-app
yarn create plinthjs-app
npx create-plinthjs-app

All of these start the same interview. Add a name to skip the first question (plinth new blog); the name is also the directory that gets created.

The name must look like an npm package name: lower-case, no more than 214 characters, made of letters, digits, hyphens, dots and underscores, and not starting with a dot or underscore. A name such as Blog is rejected with the message Project name must be lower-case.. If the target directory already exists and is not empty, the scaffolder stops with an error and writes nothing.

The interview ​

In a terminal, the scaffolder asks for whatever you did not pass as a flag, one question at a time:

  1. Project name. Type it, or press Enter for my-plinthjs-app.
  2. Starter. A web application (pages, forms, sessions and sign-in) or a JSON API.
  3. Frontend (web only). Plinth templates (server-rendered, with authentication pages), Vue or React.
  4. Database. SQLite (no setup), MySQL or MariaDB.
  5. Git. Whether to initialise a repository.
  6. Install. Whether to install dependencies now.
  7. Package manager. Asked only when you chose to install and more than one of npm, pnpm, yarn and bun is installed.
  8. Migrations. Asked only for SQLite when you chose to install: whether to run the migrations now (and, for the Plinth templates starter, create the demo account).

Choose from a list with the up and down arrow keys and press Enter. Answer yes or no questions with y or n, or the left and right arrow keys. Press Ctrl+C at any point to cancel; nothing is written until the questions are done.

Each step that follows the questions shows a spinner and a tick:

text
✔ Creating blog
✔ Initialising a git repository
✔ Installing dependencies with pnpm
✔ Running the database migrations
✔ Creating the demo account

Every flag below answers its question ahead of time, so plinth new blog --react --mysql --no-git only asks what is left.

Choosing a stack ​

A project is either a web app or a JSON API. Pass a flag to choose, or answer the question:

FlagStack
--webRoutes, controllers and a frontend (the default)
--apiLean JSON controllers with request validation and no views
--stack=webSame as --web
--stack=apiSame as --api
bash
npx create-plinthjs-app blog --web
npx create-plinthjs-app billing-api --api

Choosing a frontend ​

For the web stack you also choose a frontend:

FlagFrontend
--plinthServer-rendered .plinth views, with a full authentication starter (the default)
--vueA Vue single-page app bundled by Vite
--reactA React single-page app bundled by Vite
--frontend=plinthSame as --plinth; also accepts vue and react

A frontend flag implies the web stack, so you do not need to add --web:

bash
npx create-plinthjs-app blog --react

If you pass --api, any frontend flag is ignored because the API stack has no frontend.

The other options ​

FlagWhat it does
--database=sqlite|mysql|mariadbChoose the database; also --sqlite, --mysql, --mariadb and --db=
--pm=npm|pnpm|yarn|bunChoose the package manager to install with; also --package-manager=
--git, --no-gitInitialise (or skip) a git repository
--install, --no-installInstall (or skip) dependencies
--migrate, --no-migrateRun (or skip) the migrations and the demo account seeder after installing (SQLite)
--dry-runPrint the files that would be created and write nothing
--linkWrite workspace:* for the @plinthjs/* dependencies instead of the published range
-h, --helpShow the help text
-v, --versionShow the scaffolder version

Unrecognised flags are ignored, and an unrecognised value for --stack, --frontend, --database or --pm is ignored as well, so a typo falls back to a question or to the default rather than failing.

With MySQL or MariaDB the scaffolder sets DB_CONNECTION in .env and .env.example and names the database after your project (DB_DATABASE=blog). You still fill in DB_HOST, DB_USERNAME and DB_PASSWORD and create the database yourself, which is why it does not offer to run the migrations for you.

--dry-run is a good way to see what a stack contains before committing to it:

bash
npx create-plinthjs-app blog --vue --dry-run
# Would create 68 files in blog/:
#   .editorconfig
#   .gitattributes
#   .env.example
#   ...

--link is meant for working inside the Plinth monorepo, where the @plinthjs/* packages resolve through the workspace. In a normal project you will not use it.

Scripts and CI ​

When the scaffolder is not attached to a terminal (in a script or a CI job) it never asks anything and never waits for input. It prints nothing interactive and falls back to the defaults: the name my-plinthjs-app, the web stack, the Plinth templates frontend, SQLite, git and install on, and the package manager that started it. It does not run the migrations unless you pass --migrate. Pass the flags you care about to be explicit:

bash
npx create-plinthjs-app shop --api --no-git --no-install

What the scaffolder does ​

When the questions are done, it runs these steps in order:

  1. It writes every file for the chosen stack into the new directory.
  2. It creates .env from .env.example, sets the database you chose and replaces APP_KEY with a freshly generated random key, so the app can boot immediately. You do not need a separate key-generation step.
  3. Unless you chose --no-git, and if git is available, it runs git init and stages the files. It does not make a commit.
  4. Unless you chose --no-install, it runs your package manager's install command.
  5. If you chose to migrate, it runs plinth migrate and, for the Plinth templates starter, plinth db:seed.
  6. It prints the next steps, leaving out the ones it has already done.

Every step after writing the files is best-effort: a missing git or a failed install is reported as a hint, with the command to run yourself, and does not abort the scaffold.

Running the application ​

For the default web stack, the scaffolder prints these next steps (it leaves out the ones it already ran, for example when you let it run the migrations):

bash
cd blog
npx plinth migrate
npx plinth db:seed
npm run dev

migrate creates the SQLite database at storage/database.sqlite and its tables. db:seed creates a demo account. npm run dev starts the server, which listens on port 3000 unless you set PORT. Open http://localhost:3000 and sign in with test@example.com and password.

The API stack has no seeded account. After migrate, start it the same way and request the health endpoint:

bash
npm run dev
curl http://localhost:3000/api/health

The Vue and React stacks need Vite running as well. Start the frontend dev server in a second terminal:

bash
npm run frontend:dev   # in a second terminal
npm run dev

npm run dev uses tsx watch, so the server restarts when you change a source file. Restart it yourself after editing .env, because the environment file is read once at startup.

npx plinth runs the application's console. Run npx plinth list to see every command, including the generators such as make:controller and make:migration. See The plinth command for how it works and Console for writing your own commands.

Using MySQL instead of SQLite ​

The generated app is ready for MySQL or MariaDB. Choose MySQL or MariaDB when the scaffolder asks (or pass --mysql or --mariadb) and it writes the connection settings for you. To switch an existing app, switch the connection in .env. The mysql2 client is already listed in the app's dependencies; if you removed it, install it again:

bash
npm install mysql2
bash
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=secret

Then run npx plinth migrate. Note that DB_DATABASE is the file path for SQLite and the database name for MySQL, so change it when you switch. See Database for details.

Installing packages individually ​

You do not need the scaffolder to use Plinth. Each package is a normal npm package that you can add to any project:

bash
pnpm add @plinthjs/core @plinthjs/http
pnpm add @plinthjs/cache

The packages are written in TypeScript and ship their own declarations, so there are no separate @types packages. Both ES modules and CommonJS are supported:

ts
import { Container } from '@plinthjs/core'
import { arrayCache } from '@plinthjs/cache'

Packages depend on each other only when they must, so adding one pulls in just its real dependencies. For example, @plinthjs/session depends on @plinthjs/http, while @plinthjs/cache needs only @plinthjs/support. If your code only needs to describe the shape of a service, depend on the types in @plinthjs/contracts instead of a concrete package.

TIP

A published package range of ^0.1.0 is what the scaffolder writes into the generated package.json. Because the framework is pre-1.0, check each package's changelog when you upgrade.

Next steps ​

Read Configuration to see how the generated app reads its settings, and Directory Structure for a tour of the files you just created.

Released under the MIT License.