KeystoneJS Installation and Setup
KeystoneJS 6 requires PostgreSQL or MySQL/SQLite (for development) and Node.js 18+. Installation takes 20–30 minutes, but correct initial configuration saves hours later.
Project Initialization
npm create keystone-app@latest my-project
# Select: PostgreSQL, starter template (blog or todo)
cd my-project
npm install
Creates structure with keystone.ts, schema.ts, and example List. Immediately switch SQLite to PostgreSQL:
// keystone.ts
db: {
provider: 'postgresql',
url: process.env.DATABASE_URL || 'postgresql://user:pass@localhost:5432/keystone_dev',
enableLogging: true,
idField: { kind: 'uuid' }, // instead of autoincrement
},
Environment Variables
# .env
DATABASE_URL=postgresql://keystone:secret@localhost:5432/keystone_dev
SESSION_SECRET=supersecretkey32charsmin
FRONTEND_URL=http://localhost:3001
BASE_URL=http://localhost:3000
First Run and Migrations
# Run in dev mode (auto-migrate)
npx keystone dev
# First migration created automatically
# In production — explicitly:
npx keystone prisma migrate deploy
After launch available:
-
Admin UI:
http://localhost:3000— create first user -
GraphQL API:
http://localhost:3000/api/graphql - GraphQL Playground: enabled only in development
CORS and Server Options Setup
server: {
cors: { origin: ['http://localhost:3001'], credentials: true },
port: parseInt(process.env.PORT || '3000'),
maxFileSize: 200 * 1024 * 1024, // 200MB for file upload
},
TypeScript and tsconfig
KeystoneJS generates types automatically in .keystone/types.ts. Add to tsconfig.json:
{
"compilerOptions": {
"target": "ES2019",
"module": "CommonJS",
"lib": ["ES2019"],
"strict": true,
"paths": {
".keystone/types": ["./.keystone/types"]
}
}
}
Basic installation and PostgreSQL environment setup — 2–4 hours, including creating first Lists and test deployment.







