Dev Command
Start development server with hot reload and automatic restarts
Overview
The dev command starts your Dwex application in development mode with hot reload. It automatically restarts your server when files change, clearing the console and showing restart timing for a smooth development experience.
Usage
bunx dwex devFeatures
- Hot Reload - Automatically restarts on file changes
- Clear Console - Clean output on each restart
- Timing Info - Shows startup and restart duration
- Port Configuration - Customize server port
- Colorful Output - Clear status messages with colors
Options
-p, --port <port>
Specify a custom port:
bunx dwex dev --port 9929
bunx dwex dev -p 4000How It Works
The dev command:
- Reads entry point from
index.ts(or config) - Starts your app with Bun's
--watchflag - Monitors file changes in your project
- Clears console and restarts on changes
- Shows timing information for each restart
Output
On first start:
ℹ Starting Dwex development server...
✔ Server ready in 245ms
➜ Local: http://localhost:9929
➜ Watching for changes...On file change:
ℹ File change detected, restarting...
✔ Server restarted in 123ms
➜ Local: http://localhost:9929Environment Variables
Set environment variables for development:
PORT=8080 bunx dwex devOr create a .env file:
PORT=9929
NODE_ENV=development
DATABASE_URL=postgresql://localhost/mydbConfiguration
Customize dev server in dwex.config.ts:
export default {
entry: "index.ts",
port: 9929,
};See Configuration for all options.
Watching Files
The dev server uses Bun's native --watch flag, which watches:
- All TypeScript/JavaScript files
- JSON configuration files
- Files imported by your application
Files not watched:
node_modules/dist/or build output.git/- Files in
.gitignore
Performance
Development mode is optimized for fast restarts:
- Initial start: ~200-500ms
- Hot restarts: ~100-300ms
- No build step required (uses Bun's JIT)
Tips for Development
Fast Restarts
Keep restart times fast by:
- Using lazy imports for heavy modules
- Avoiding expensive initialization logic
- Using environment-based conditional imports
// Lazy load heavy modules
if (process.env.NODE_ENV === "development") {
const { devTool } = await import("./dev-tools");
}Multiple Instances
Run multiple apps on different ports:
# Terminal 1
bunx dwex dev --port 9929
# Terminal 2
bunx dwex dev --port 4000Debug Mode
Enable verbose logging:
import "reflect-metadata";
import { DwexFactory } from "@dwex/core";
import { RootModule } from "./root.module";
const app = await DwexFactory.create(RootModule, {
logger: ["log", "error", "warn", "debug", "verbose"],
});
await app.listen(9929);Graceful Shutdown
The dev server handles shutdown gracefully:
- Press
Ctrl+Cto stop - Server closes active connections
- Process exits cleanly
Troubleshooting
Port Already in Use
If port is already taken:
bunx dwex dev --port 9929Or find and kill the process:
# macOS/Linux
lsof -ti:9929 | xargs kill -9
# Or use a different port in configChanges Not Detected
If hot reload isn't working:
- Ensure files are in the project directory
- Check file isn't in
.gitignore - Restart the dev server manually
Slow Restarts
If restarts are slow:
- Check for heavy synchronous operations during app initialization
- Use lazy imports for large dependencies
- Profile startup with
console.time()
console.time("startup");
const app = await DwexFactory.create(RootModule);
console.timeEnd("startup");Comparison with Production
| Feature | Dev Mode | Production Build |
|---|---|---|
| Startup | ~200-500ms | ~50-100ms |
| Hot Reload | ✅ Yes | ❌ No |
| Minified | ❌ No | ✅ Yes |
| Sourcemaps | ✅ Inline | ⚙️ Configurable |
| Bundle Size | N/A | Optimized |
Next Steps
- Build Command - Create production builds
- Generate Command - Scaffold code quickly
- Configuration - Customize dev server