NestJS startup unbelievably slow in development
Try to set env TS_NODE_TRANSPILE_ONLY=true
.
e.g. TS_NODE_TRANSPILE_ONLY=true ts-node -r tsconfig-paths/register src/main.ts
docs: https://github.com/TypeStrong/ts-node#cli-and-programmatic-options
It's speed up my app startup
One option is to use tsc-watch instead of ts-node and nodemon. You can set up the start command in your start:dev as follows:
{ //this is assuming you're building to the dist folder ... "start:dev": "tsc-watch --onSuccess \"node dist/main.js\" --onFailure \"echo There was a problem with the build!\" -p tscfonig.json" ...}
In my experience I ran into too many problems with ts-node
and registering routes, plus load times were killing me. With tsc-watch
I get a fresh build of the project, rebuilding only the files that were changed. This way you're also testing that tsc
works while developing.
I also use a tsconfig-bootstrap command to import my custom routes (defined in my tsconfig) and add that into my start command with node -r path/to/my/script.js dist/main.js
.
Hope this helps you a bit!
install the latest version of the @nestjs/cli
, both globally and locally:
$ npm install -g @nestjs/cli$ cd /some/project/root/folder$ npm install -D @nestjs/cli
replace/make sure you have the below scripts defined in package.json
"build": "nest build","start": "nest start","start:dev": "nest start --watch","start:debug": "nest start --debug --watch",
make sure you have vs code auto attach on
run
npm run start:dev