1. Create your project
Generate it
Open a terminal in the folder where you keep your projects and run:
npx selfauth@latest init notes-app --backend express --database sqlite --frontend nonenotes-app is the name of the new folder, and it's also the project's name. SelfAuth shows you the list of files it's about to create and writes them. It takes a few seconds.
If you leave out the options, npx selfauth@latest init notes-app asks you the same questions one at a time.
Using PostgreSQL, MySQL or MongoDB instead?
Change --database:
npx selfauth@latest init notes-app --backend express --database postgresql --frontend noneThe values are postgresql, mysql, sqlite, mongodb and memory. You'll need an empty database ready, and in the next step you'll put its address in .env.
Want React or Vue pages too?
Use --frontend react or --frontend vue. Your project then has two folders: server/ holds the Express API and client/ holds the pages. Every file this guide mentions is inside server/, so src/routes/index.ts becomes server/src/routes/index.ts. Run the npm and npx selfauth commands from the top notes-app folder, as written.
Install and set up the database
cd notes-app
npm installNext, create your settings file by copying the example:
cp .env.example .envCopy-Item .env.example .env.env holds settings that differ between your computer and production: the port, your frontend's address, and the database address. For SQLite it already points at a file called app.db, so you don't need to change anything.
The DATABASE_URL for other databases
Open .env and set DATABASE_URL to your database:
# PostgreSQL
DATABASE_URL=postgresql://postgres:secret@localhost:5432/notes
# MySQL
DATABASE_URL=mysql://root:secret@localhost:3306/notes
# MongoDB
DATABASE_URL=mongodb://localhost:27017/notesNow create the tables SelfAuth needs. First look at what will happen:
npx selfauth db planPending migrations (1):
• 20261116085533_selfauth_init (prisma/migrations/20261116085533_selfauth_init/migration.sql)
✓ Nothing here loses data or touches SelfAuth's tables.A migration is a file of SQL that changes the database. This one creates SelfAuth's tables: users, sessions, roles and so on. plan reads it and tells you whether it would lose any data. It wouldn't, so apply it:
npx selfauth db migrateThen write the roles from your configuration into the database:
npm run db:seedSynchronized roles: user, adminMongoDB
MongoDB has no SQL migrations. npx selfauth db migrate creates the indexes SelfAuth needs instead (the one that keeps emails unique, for example). The commands are the same.
Check it worked
npx selfauth validateThe last line should be All checks passed. You now have a working Express API with sign-up and sign-in. Next you'll start it and try it.
If something went wrong
npm installfailed on Windows with no explanation. Older versions of the CLI couldn't start npm on Windows. Runnpm installyourself insidenotes-app. The generated files are fine.DATABASE_URL is not set. You skipped copying.env.exampleto.env, or you ran the command outside thenotes-appfolder.Can't reach database server(PostgreSQL, MySQL). The database isn't running, or the address, user or password inDATABASE_URLis wrong.
Next: Run it and sign in