0
# Development Server
1
2
Start NestJS applications in development mode with hot reloading, debugging support, and comprehensive configuration options. The development server provides an efficient workflow for rapid application development and testing.
3
4
## Capabilities
5
6
### Start Command
7
8
Launches your NestJS application with development-focused features and extensive customization options.
9
10
```bash { .api }
11
# Start application
12
nest start [app] [options]
13
14
# Options:
15
-c, --config [path] # Path to nest-cli configuration file
16
-p, --path [path] # Path to tsconfig file
17
-w, --watch # Run in watch mode (live-reload)
18
-b, --builder [name] # Builder to be used (tsc, webpack, swc)
19
--watchAssets # Watch non-ts (e.g., .graphql) files mode
20
-d, --debug [hostport] # Run in debug mode (with --inspect flag)
21
--webpack # Use webpack for compilation (deprecated, use --builder)
22
--webpackPath [path] # Path to webpack configuration
23
--type-check # Enable type checking (when SWC is used)
24
--tsc # Use typescript compiler for compilation
25
--sourceRoot [sourceRoot] # Points at the root of the source code
26
--entryFile [entryFile] # Path to the entry file
27
-e, --exec [binary] # Binary to run (default: "node")
28
--preserveWatchOutput # Use "preserveWatchOutput" option when using tsc watch mode
29
--shell # Spawn child processes within a shell (default: true)
30
--no-shell # Do not spawn child processes within a shell
31
--env-file [path] # Path to an env file (.env) to be loaded
32
```
33
34
**Usage Examples:**
35
36
```bash
37
# Basic development server
38
nest start
39
40
# Start with watch mode (hot reload)
41
nest start --watch
42
43
# Start specific app in monorepo
44
nest start api-gateway
45
46
# Start with debug mode
47
nest start --debug
48
nest start --debug 0.0.0.0:9229
49
50
# Start with asset watching
51
nest start --watch --watchAssets
52
53
# Start with specific builder
54
nest start --builder webpack
55
nest start --builder swc --type-check
56
57
# Start with environment file
58
nest start --env-file .env.development
59
60
# Start with custom entry point
61
nest start --entryFile src/main.ts
62
63
# Start with custom binary
64
nest start --exec "node --max-old-space-size=4096"
65
```
66
67
## Development Features
68
69
### Watch Mode
70
71
Automatically restart the application when files change:
72
73
```bash { .api }
74
# Enable hot reloading
75
nest start --watch
76
77
# Watch with asset monitoring
78
nest start --watch --watchAssets
79
```
80
81
**Watched File Types:**
82
- TypeScript files (.ts)
83
- JavaScript files (.js)
84
- JSON configuration files
85
- GraphQL schema files (with --watchAssets)
86
- Protocol buffer definitions (with --watchAssets)
87
88
### Debug Mode
89
90
Enable Node.js debugging with Inspector protocol:
91
92
```bash { .api }
93
# Debug on default port (9229)
94
nest start --debug
95
96
# Debug on specific host:port
97
nest start --debug 0.0.0.0:9229
98
nest start --debug localhost:9229
99
100
# Debug with watch mode
101
nest start --debug --watch
102
```
103
104
**Debug Configuration:**
105
- Enables `--inspect` flag automatically
106
- Supports Chrome DevTools
107
- Compatible with VS Code debugger
108
- Works with watch mode for continuous debugging
109
110
### Environment Configuration
111
112
Load environment variables from files:
113
114
```bash { .api }
115
# Single environment file
116
nest start --env-file .env.development
117
118
# Multiple environment files
119
nest start --env-file .env --env-file .env.local
120
```
121
122
## Build System Integration
123
124
### TypeScript Compiler
125
126
```bash { .api }
127
# Use TypeScript compiler
128
nest start --builder tsc --watch
129
130
# With preserved watch output
131
nest start --builder tsc --watch --preserveWatchOutput
132
```
133
134
### Webpack Development Server
135
136
```bash { .api }
137
# Use Webpack with HMR
138
nest start --builder webpack --watch
139
140
# Custom webpack configuration
141
nest start --builder webpack --webpackPath webpack.dev.js
142
```
143
144
### SWC for Fast Compilation
145
146
```bash { .api }
147
# Use SWC for fast development builds
148
nest start --builder swc --watch
149
150
# SWC with type checking
151
nest start --builder swc --type-check --watch
152
```
153
154
## Process Management
155
156
### Shell Configuration
157
158
Control how child processes are spawned:
159
160
```bash { .api }
161
# Use shell (default)
162
nest start --shell
163
164
# No shell spawning
165
nest start --no-shell
166
```
167
168
### Custom Binary Execution
169
170
Specify the runtime binary and options:
171
172
```bash { .api }
173
# Default Node.js
174
nest start --exec node
175
176
# Node with memory optimization
177
nest start --exec "node --max-old-space-size=4096"
178
179
# Node with experimental features
180
nest start --exec "node --experimental-modules"
181
```
182
183
## Project Structure Support
184
185
### Monorepo Applications
186
187
```bash { .api }
188
# Start specific application
189
nest start api-gateway
190
nest start user-service
191
nest start payment-service
192
193
# Start with project-specific config
194
nest start api-gateway --config apps/api-gateway/nest-cli.json
195
```
196
197
### Custom Entry Points
198
199
```bash { .api }
200
# Custom entry file
201
nest start --entryFile src/main.ts
202
nest start --entryFile apps/api/src/main.ts
203
204
# Custom source root
205
nest start --sourceRoot src
206
nest start --sourceRoot apps/api/src
207
```
208
209
## Configuration Files
210
211
### nest-cli.json Development Settings
212
213
```json
214
{
215
"collection": "@nestjs/schematics",
216
"sourceRoot": "src",
217
"compilerOptions": {
218
"builder": "webpack",
219
"typeCheck": true,
220
"assets": ["**/*.proto", "**/*.graphql"],
221
"watchAssets": true
222
},
223
"generateOptions": {
224
"spec": false
225
}
226
}
227
```
228
229
### Environment File Loading
230
231
Supported environment file formats:
232
233
```bash
234
# .env files
235
.env
236
.env.local
237
.env.development
238
.env.development.local
239
```
240
241
Environment file example:
242
```env
243
NODE_ENV=development
244
PORT=3000
245
DATABASE_URL=postgresql://localhost:5432/nestjs_dev
246
LOG_LEVEL=debug
247
```
248
249
## Performance Optimization
250
251
### Fast Development Builds
252
253
```bash { .api }
254
# Fastest startup with SWC
255
nest start --builder swc --watch
256
257
# Balance speed and features with Webpack
258
nest start --builder webpack --watch
259
260
# Full type safety with TypeScript
261
nest start --builder tsc --watch --preserveWatchOutput
262
```
263
264
### Memory Management
265
266
```bash { .api }
267
# Increase Node.js memory limit
268
nest start --exec "node --max-old-space-size=8192"
269
270
# Enable garbage collection optimization
271
nest start --exec "node --optimize-for-size"
272
```
273
274
## Development Workflow Integration
275
276
### Common Development Commands
277
278
```bash { .api }
279
# Standard development workflow
280
nest start --watch --debug
281
282
# Full-featured development with assets
283
nest start --watch --watchAssets --debug --env-file .env.development
284
285
# Fast iteration development
286
nest start --builder swc --watch --type-check
287
```
288
289
### IDE Integration
290
291
The development server works seamlessly with:
292
- VS Code with Node.js debugging
293
- WebStorm with built-in Node.js support
294
- Chrome DevTools for debugging
295
- Any editor with Language Server Protocol support
296
297
## Error Handling
298
299
### Invalid Builder Options
300
301
```bash
302
# Invalid builder name
303
nest start --builder invalid
304
# Error: Invalid builder option: invalid. Available builders: tsc, webpack, swc
305
```
306
307
### Process Exit Handling
308
309
The CLI properly handles process termination and cleanup:
310
- Graceful shutdown on SIGTERM/SIGINT
311
- Child process cleanup
312
- File watcher cleanup
313
- Port release
314
315
### Error Recovery
316
317
In watch mode, the CLI recovers from compilation errors:
318
- Continues watching after TypeScript errors
319
- Restarts on successful compilation
320
- Preserves debug connections when possible