| description | Use Bun instead of Node.js, npm, pnpm, or vite. |
|---|---|
| globs | *.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json |
| alwaysApply | false |
Default to using Bun instead of Node.js.
- Use
bun <file>instead ofnode <file>orts-node <file> - Use
bun testinstead ofjestorvitest - Use
bun build <file.html|file.ts|file.css>instead ofwebpackoresbuild - Use
bun installinstead ofnpm installoryarn installorpnpm install - Use
bun run <script>instead ofnpm run <script>oryarn run <script>orpnpm run <script> - Bun automatically loads .env, so don't use dotenv.
- Don't install specific package versions, always install the latest version. Prefer installing using the
bun addcommand over adding it to package.json manually
Bun.serve()supports WebSockets, HTTPS, and routes. Don't useexpress.bun:sqlitefor SQLite. Don't usebetter-sqlite3.Bun.redisfor Redis. Don't useioredis.Bun.sqlfor Postgres. Don't usepgorpostgres.js.WebSocketis built-in. Don't usews.- Prefer
Bun.fileovernode:fs's readFile/writeFile - Bun.$
lsinstead of execa.
Use bun test to run tests.
import { test, expect } from "bun:test";
test("hello world", () => {
expect(1).toBe(1);
});Use HTML imports with Bun.serve(). Don't use vite. HTML imports fully support React, CSS, Tailwind.
Server:
import index from "./index.html"
Bun.serve({
routes: {
"/": index,
"/api/users/:id": {
GET: (req) => {
return new Response(JSON.stringify({ id: req.params.id }));
},
},
},
// optional websocket support
websocket: {
open: (ws) => {
ws.send("Hello, world!");
},
message: (ws, message) => {
ws.send(message);
},
close: (ws) => {
// handle close
}
},
development: {
hmr: true,
console: true,
}
})HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. <link> tags can point to stylesheets and Bun's CSS bundler will bundle.
<html>
<body>
<h1>Hello, world!</h1>
<script type="module" src="./frontend.tsx"></script>
</body>
</html>With the following frontend.tsx:
import React from "react";
// import .css files directly and it works
import './index.css';
import { createRoot } from "react-dom/client";
const root = createRoot(document.body);
export default function Frontend() {
return <h1>Hello, world!</h1>;
}
root.render(<Frontend />);Then, run index.ts
bun --hot ./index.tsFor more information, read the Bun API docs in node_modules/bun-types/docs/**.md.
PingThing is a network reliability testing application built with Bun and TypeScript. It monitors network connectivity by periodically pinging configured services and performing diagnostic traceroutes when failures occur. All network incidents are logged and stored for analysis.
- CLI Interface: Command-line interface using the
argpackage for configuration - Network Monitoring: Periodic ping tests to configured endpoints
- Diagnostic Tools: Automated traceroute when ping failures are detected
- Data Persistence: SQLite database using
bun:sqlitefor incident storage - Logging: Structured logging with the
consolapackage - API: Fastify-based REST API for accessing incident data
- Multi-platform: Docker Compose deployment for Raspberry Pi, Linux, and macOS
-
Core Infrastructure
- Set up TypeScript project with Bun
- Configure CLI argument parsing
- Initialize SQLite database for incident storage
- Set up structured logging
-
Network Testing
- Implement ping functionality for multiple endpoints
- Add traceroute diagnostics for failed pings
- Create periodic monitoring scheduler
- Store all findings in database
-
API & Deployment
- Build Fastify API for incident data access
- Create Docker Compose configuration
- Add cross-platform deployment support
# Start monitoring with default configuration
bun start
# Monitor specific hosts with custom interval
bun start --hosts google.com,github.com --interval 30
# Start API server
bun run api
# View incident history
bun run report