I work on a project using Nest, where the "start" config in the package.json looks like this:
"start:dev": "nest start --watch",
"start": "node dist/main.js",
and I wonder why the the second line does not simply use "nest: start". Both seem to work the same. The documentation states that:
nest startsimply ensures the project has been built (same asnest build), then invokes thenodecommand in a portable, easy way to execute the compiled application.
I don’t see why anyone would want to run a project without ensuring it was built first. So is there any reason not to use nest start? Maybe performance? Are there other meaningful differences?
Generally speaking the @nestjs/cli is a great dev tool, but it doesn't have much use in production. You usually don't have changes to your code that you need to auto-recompile and restart your server with (the --watch flag), you don't need to do live debugging (the --debug flag) and you usually don't need to compile your code once in production, as you should be sending the transpiled JS to production instead of the source code. Due to all of these factors, there's not really a reason to use nest start in production.
Locally, however, it's an awesome tool to allow for quick restarts of the server, and to generate files using the nest g command. The nest start command itself does check to see that the project is already compiled, but it only checks that a dist exists, and if so it's good, no matter how old that dist is, which is why the --watch flag is usually better to add to it, so that you always get a recompile to happen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With