pnpm dev command starts a development server with Hot Module Replacement (HMR) support. When you modify code, changes are instantly reflected without restarting the server.
Basic Usage
- Auto-restart: Automatic server restart on code changes
- TypeScript support: Run .ts files directly
- Source map support: Accurate line numbers on errors
- Keyboard shortcuts: Shortcuts for quick actions
Subcommands
You can run API and Web separately.
Running API and Web in separate terminals:
How It Works
pnpm dev internally uses the following tools:
Important: These packages are automatically provided by Sonamu, so no separate installation is needed.
Execution Process
- Execute
src/index.tsas entry point - Transform and execute TypeScript files immediately
- Detect file changes
- Replace only changed modules (HMR)
- Full restart only when necessary
Keyboard Shortcuts
You can use the following shortcuts while the development server is running:Shortcut Usage Examples
Server restart:Environment Variables
The development server automatically sets the following environment variables:
You can check environment variables in code:
How HMR Works
Cases That Auto-restart
The server automatically restarts when modifying these files:- Entity files (
*.entity.ts) - Model files (
*.model.ts) - Config files (
sonamu.config.ts) - Migration files
Cases Reflected Instantly (HMR)
Changes to these files are reflected instantly without server restart:- General business logic
- Utility functions
- Service layer
Troubleshooting
Server Wonβt Start
Problem: Port already in useHMR Not Working
Problem: Code changes not reflected Solution:TypeScript Errors
Problem: Server wonβt start due to type errors Solution:Practical Tips
1. Fast Development Cycle
Modify code and test immediately:2. Check Logs
Development server outputs all logs to console:3. Debugging
Source maps are enabled for accurate line numbers:Differences from Production
Next Steps
build
Build for production
HMR
Learn more about HMR system