The Rikta CLI (@riktajs/cli) provides commands to scaffold, develop, and build Rikta applications.
# Global installation (recommended)
npm install -g @riktajs/cli
# Or use npx (no installation)
npx @riktajs/cli <command>| Command | Description |
|---|---|
rikta new <name> |
Create a new Rikta project |
rikta dev |
Start development server with hot reload |
rikta build |
Build for production |
The new command scaffolds a complete Rikta project:
rikta new my-api
cd my-apiThis creates:
my-api/
├── src/
│ ├── controllers/
│ │ └── app.controller.ts # REST controller with @Controller
│ ├── services/
│ │ └── greeting.service.ts # Injectable service
│ └── index.ts # Entry point
├── package.json
├── tsconfig.json
├── .gitignore
└── README.md
// src/controllers/app.controller.ts
import { Controller, Get } from '@riktajs/core';
import { Autowired } from '@riktajs/core';
import { GreetingService } from '../services/greeting.service.js';
@Controller()
export class AppController {
@Autowired()
private greetingService!: GreetingService;
@Get('/')
index() {
return { message: this.greetingService.getGreeting() };
}
@Get('/health')
health() {
return { status: 'ok', timestamp: new Date().toISOString() };
}
}// src/services/greeting.service.ts
import { Injectable } from '@riktajs/core';
@Injectable()
export class GreetingService {
getGreeting(): string {
return 'Welcome to Rikta! 🚀';
}
}// src/index.ts
import 'reflect-metadata';
import { Rikta, Container } from '@riktajs/core';
import { GreetingService } from './services/greeting.service.js';
const container = new Container();
container.register(GreetingService);
const app = await Rikta.create({
port: 3000,
autowired: ['./src/controllers'],
container,
});
await app.listen();
console.log('🚀 Server running on http://localhost:3000');The dev command provides a full development experience:
rikta dev- TypeScript Watch Mode: Automatically recompiles on file changes
- Hot Reload: Server restarts when compilation completes
- Error Display: Clear TypeScript error messages
- Dependency Check: Warns if
node_modulesis missing
# Custom port
rikta dev --port 8080
# Bind to specific host
rikta dev --host 127.0.0.1
# Disable watch mode
rikta dev --no-watch
# Verbose output
rikta dev --verbose- Checks for
node_modules(prompts to runnpm installif missing) - Starts
tsc --watchfor continuous compilation - Monitors TypeScript output for compilation completion
- Starts/restarts the Node.js server on successful compilation
- Displays errors on compilation failure
The build command creates optimized production output:
rikta build- Clean Build: Removes old
dist/files first - Optimized Output: Removes comments, no source maps by default
- Build Analytics: Reports file count, size, and build time
- Deploy Suggestions: Shows commands for deployment
# With source maps (for debugging production issues)
rikta build --sourcemap
# Custom output directory
rikta build --outDir build
# Keep previous files
rikta build --no-clean
# Skip comment removal
rikta build --no-minify
# Verbose mode
rikta build --verbose───────────────────────────
│ Rikta Production Build │
───────────────────────────
[1/5] Checking project...
✔ Rikta project detected
[2/5] Detecting TypeScript configuration...
✔ Using tsconfig.json
[3/5] Cleaning dist folder...
✔ Output folder cleaned
[4/5] Compiling TypeScript...
✔ TypeScript compilation complete
[5/5] Build summary...
✔ Build completed successfully!
⏱️ Build time: 1.23s
📦 Output: /path/to/dist
📄 Files: 5 JavaScript files
📊 Size: 12.34 KB
✨ Optimizations: no source maps, comments removed
📦 Estimated deploy size:
dist: 12.34 KB
node_modules: 2.45 MB
─────────────────────
Total: 2.46 MB
🚀 Deploy commands:
# Create deployment package
zip -r deploy.zip dist node_modules package.json
# Or use Docker
docker build -t my-app .
For production-specific settings, create tsconfig.build.json:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": false,
"sourceMap": false,
"removeComments": true
},
"exclude": [
"**/*.test.ts",
"**/*.spec.ts",
"tests/**/*"
]
}The CLI automatically uses this file if it exists.
# Build
rikta build
# Package
zip -r deploy.zip dist node_modules package.json
# Deploy to AWS Lambda, Vercel, etc.FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY dist ./dist
EXPOSE 3000
CMD ["node", "dist/index.js"]docker build -t my-app .
docker run -p 3000:3000 my-app# Build
rikta build
# Start in production
NODE_ENV=production node dist/index.js
# Or with PM2
pm2 start dist/index.js --name my-appMake sure your package.json includes @riktajs/core as a dependency:
{
"dependencies": {
"@riktajs/core": "^0.4.0"
}
}Run npm install before using rikta dev or rikta build:
npm install
rikta devThe CLI will display errors from TypeScript. Fix the reported issues in your code and the server will automatically restart (in dev mode).
Use a different port:
rikta dev --port 3001Or kill the process using the port:
# Find process
lsof -i :3000
# Kill it
kill -9 <PID>