Getting Started
What is Pikku?β
Pikku is a TypeScript backend that adapts β write your logic once and run it anywhere. Like a chameleon, Pikku keeps your core logic intact while adapting to HTTP, WebSockets, queues, scheduled tasks, and more. Whether you deploy to Express, AWS Lambda, Cloudflare Workers, or any other runtime, your business logic stays the same. This means you can start simple and evolve your architecture without refactoring.
This guide covers the core fundamentals of Pikku through a practical setup walkthrough.
Prerequisitesβ
Ensure that Node.js (version >= 18) is installed on your operating system.
Installationβ
Begin by creating a new Pikku project using npm create:
- npm
- Yarn
- pnpm
- Bun
npm create pikku@latest
npm create pikku@latest
# couldn't auto-convert command
npm create pikku@latest
# couldn't auto-convert command
bunx create-pikku@latest
This will guide you through setting up a project:
The starter project includes example functions and routes so you can immediately see Pikku in action.
Run and Verifyβ
After installation completes, navigate to your project directory and start the development server:
- npm
- Yarn
- pnpm
- Bun
npm start
yarn start
pnpm start
bun start
The server will start on http://localhost:3000. You can verify it's working by testing the example endpoint:
curl http://localhost:3000/api/hello-world
You should see a response from your first Pikku function!
Your First Functionβ
Let's look at the Hello World function that came with the starter. Open functions/hello-world.function.ts:
import { pikkuFunc } from '@pikku/core'
export const helloWorld = pikkuFunc({
func: async () => {
return { message: 'Hello from Pikku!' }
}
})
This function is wired to an HTTP route in http.ts:
import { wireHTTP } from '@pikku/core'
import { helloWorld } from './functions/hello-world.function'
wireHTTP({ route: '/api/hello-world', func: helloWorld })
That's it! The same function could also be wired to WebSockets, queues, or scheduled tasks without changing its implementation. This is Pikku's core philosophy: write once, run anywhere.
Understanding the CLIβ
Pikku includes a CLI tool that generates code as you work. When you modify your functions or wirings, run:
- npm
- Yarn
- pnpm
- Bun
npm run pikku watch
yarn pikku watch
pnpm run pikku watch
bun run pikku watch
This runs the CLI in watch mode, which:
- Scans your codebase for
pikkuFuncdefinitions and wirings - Generates type definitions to provide autocomplete and type safety
- Creates validation schemas for your functions
- Indexes routes and channels for fast lookup
The CLI generates two key files you'll import in your code:
#pikku/pikku-types.gen.tsβ Type definitions for your entire API#pikku/pikku-bootstrap.gen.tsβ Bootstrap code that wires up all your functions
These files are regenerated whenever you change your functions or wirings. Don't edit them manually β they're automatically kept in sync with your source code.
Project Structureβ
Here's a brief overview of the core files:
| File | Description |
|---|---|
start.ts | Server entry point that initializes your runtime and imports the bootstrap |
services.ts | Centralized management of services (database, cache, auth, etc.) available to all functions |
channels.ts | WebSocket channel definitions β where you wire functions to real-time channels |
http.ts | HTTP endpoint definitions β where you wire functions to HTTP routes |
scheduled-tasks.ts | Cron job definitions β where you wire functions to run on schedules |
types/application-types.d.ts | TypeScript type extensions for your application's services and session |
When you define wirings in http.ts, channels.ts, etc., the Pikku CLI automatically includes them in the generated bootstrap file. Your start.ts only needs to import the bootstrap β everything else is handled for you.
The Config Fileβ
The pikku.config.json file configures the Pikku CLI. It tells the CLI where to find your functions, where to generate output files, and how to process your code.
loading...
Next Stepsβ
Now that you have a working Pikku project, you're ready to dive deeper:
- Functions β Learn how to write Pikku functions and understand their signature
- Middleware β Add request processing, logging, and other cross-cutting concerns
- Services β Set up databases, caches, and other external integrations
- HTTP β Wire functions to HTTP endpoints with routing, query params, and more
- Channels β Add real-time WebSocket communication
- Scheduled Tasks β Run functions on a schedule (cron jobs)
Questions or need help? Check out our GitHub discussions β we're happy to help you get going with Pikku!