What is the --watch and --debug option in nest start

Viewed 6476

I read following documentation described nest command.

https://docs.nestjs.com/cli/scripts

According to the document, following must be added to package.json

"build": "nest build",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",

What are the --watch and --debug options?

2 Answers

According to the nestjs start docs the actual uses are as follows;

--watch

Run in watch mode (live-reload)
Alias -w

Source files which are saved with changes are automatically compiled without the need to manually run npm run start to trigger webpack compilation after every change.

For example, typescript files with changes (on save, or when using git) in src will be compiled to javascript files in dist (depending on your setup)

--debug

Run in debug mode (with --inspect flag)
Alias -d

The --debug flag actually runs the node process using the --inspect flag to allow native debugging using an IDE or otherwise. Once the node process is running, you can use an IDE to connect to to the node debug address and port (default 127.0.0.1:9229) and use breakpoints* to pause execution.

*However, do note that the above at present isn't completely accurate. IDEs usually need the --inspect-brk flag (for breakpoints) and it seems there is still a problem with the nestjs implementation.

Some IDEs (for example VS Code) can get around this with an auto-attach feature and it seems --debug is not even needed. Although very easy to set up, it is not as streamlined when developing multiple running node apps.

In general, --watch means the terminal will stay open and watch for any file changes and then reload the server. --debug means it will log more messages to the console (e.g. info or warnings), which can be helpful for debugging.

Related