Create a Flink app with one command
npm install create-flink-appThe easiest way to bootstrap a new Flink application. Creates a new project with a complete folder structure, sample handlers, schemas, repositories, and all necessary configuration files.
> Inspired by create-next-app ❤️
Create a new Flink application in one command:
``bash`
npx create-flink-app my-app
Then navigate to your app and start developing:
`bash`
cd my-app
npm install
npm run dev
The generated project includes:
``
my-app/
├── src/
│ ├── handlers/ # HTTP request handlers
│ │ └── car/
│ │ ├── GetCarById.ts
│ │ └── PostCar.ts
│ ├── repos/ # MongoDB repositories
│ │ └── CarRepo.ts
│ ├── schemas/ # TypeScript schemas
│ │ └── Car.ts
│ ├── ApplicationContext.ts # App context definition
│ └── index.ts # Application entry point
├── package.json
├── tsconfig.json
├── tsconfig.dist.json
└── .gitignore
- Handlers: Example GET and POST handlers with proper routing
- Repository: Sample MongoDB repository extending FlinkRepo
- Schemas: TypeScript interfaces for request/response validation
- Context: Pre-configured application context with dependency injection
- TypeScript: Development and distribution configs
- Package.json: Pre-configured scripts and dependencies
- Git: Sensible .gitignore for Node.js projects
`bashCreate app in current directory
npx create-flink-app .
$3
After creating your app:
`bash
Install dependencies
npm installStart development server with hot reload
npm run devBuild for production
npm run buildRun tests
npm test
`What Gets Generated
$3
`typescript
import { FlinkApp } from "@flink-app/flink";
import AppContext from "./ApplicationContext";async function start() {
await new FlinkApp({
name: "My App",
db: {
uri: "mongodb://localhost:27017/my-app",
},
plugins: [],
}).start();
}
start();
`$3
`typescript
import { GetHandler, RouteProps } from "@flink-app/flink";
import AppContext from "../../ApplicationContext";
import Car from "../../schemas/Car";export const Route: RouteProps = {
path: "/car/:id",
};
type Parameters = {
id: string;
};
const GetCarById: GetHandler = async ({ ctx, req }) => {
const car = await ctx.repos.carRepo.getById(req.params.id);
if (!car) {
return {
status: 404,
data: null,
};
}
return {
status: 200,
data: car,
};
};
export default GetCarById;
`$3
`typescript
import { FlinkRepo } from "@flink-app/flink";
import ApplicationContext from "../ApplicationContext";
import Car from "../schemas/Car";class CarRepo extends FlinkRepo {}
export default CarRepo;
`$3
`typescript
import { FlinkContext } from "@flink-app/flink";
import CarRepo from "./repos/CarRepo";interface ApplicationContext extends FlinkContext {
repos: {
carRepo: CarRepo;
};
}
export default ApplicationContext;
`Next Steps
After creating your app, you can:
1. Add more handlers: Create new files in
src/handlers/
2. Define schemas: Add TypeScript interfaces in src/schemas/
3. Add repositories: Create new repo classes in src/repos/
4. Install plugins: Add official Flink plugins for common functionality
5. Configure database: Update MongoDB connection string in src/index.tsAvailable Scripts
The generated project includes these npm scripts:
-
npm run dev: Start development server with nodemon and hot reload
- npm run build: Compile TypeScript to JavaScript
- npm test: Run Jasmine tests
- npm run test:watch: Run tests in watch mode
- npm start: Run the compiled applicationRequirements
- Node.js 14 or higher
- MongoDB (if using database features)
- npm or yarn
Configuration
$3
The project includes two TypeScript configurations:
-
tsconfig.json: For development with tests
- tsconfig.dist.json: For production builds (excludes tests)$3
Configure your database connection in
src/index.ts:`typescript
db: {
uri: process.env.MONGODB_URI || "mongodb://localhost:27017/my-app",
}
`$3
Create a
.env file for environment-specific configuration:`bash
PORT=3333
MONGODB_URI=mongodb://localhost:27017/my-app
NODE_ENV=development
`Adding Plugins
Enhance your application with official Flink plugins:
`bash
Install plugins
npm install @flink-app/jwt-auth-plugin @flink-app/s3-pluginConfigure in src/index.ts
import { jwtAuthPlugin } from "@flink-app/jwt-auth-plugin";
import { s3Plugin } from "@flink-app/s3-plugin";new FlinkApp({
name: "My App",
plugins: [
jwtAuthPlugin({ / config / }),
s3Plugin({ / config / }),
],
}).start();
`Template Source
This tool generates projects based on the official Flink template, which includes best practices and recommended project structure for Flink applications.
Troubleshooting
$3
If you get permission errors, try:
`bash
npx --yes create-flink-app my-app
`$3
If the template fails to download, you can:
1. Check your internet connection
2. Try again with
--force` flag (if available)- Flink Framework: Core Flink framework
- Flink Plugins: Official plugins for common functionality
MIT
For issues and questions:
- GitHub Issues: Flink Framework Issues
- Documentation: Check the main Flink README