NestJS application doesn't start
Hi, I'm trying to deploy a NestJS app but it gets stuck on a loop trying to start the server.
I think it is because
NODE_ENV
is set to production
on railway so the build step does not install dev dependencies which are required to build the nestjs app into the dist
directory which is needed later to run the app.
I changed NODE_ENV
to development
and the nestjs app runs successfully.
Is there any guide available on how to properly deploy a production NestJS app? should I provide my own Dockerfile? cause now it is being deployed as-is and railway is doing it's thing.
thanks in advance, please let me know if I can provide any other details19 Replies
Project ID:
N/A
developer dependencies that are required to build the app should not be in developer dependencies
why not?
aside from the fact that i'm using the default project that comes from
nest new project-name
cli command, which comes with deps/devDeps official template from nestjs,
dependencies required only at buildtime, but not at runtime, should actually be dev deps not production deps
-
what i did when deploying nestjs on other platforms, is creating a multi-layered Dockerfile which does the entire building steps ending just with an image layer containing the dist
directory built-in.
so I assume this is not contemplated specifically on nixpacks which i guess makes sensethe multi stage dockerfile you talk about is gonna produce a small image, as long as you are comfortable with those kinds of dockerfiles I highly recommend doing that over nixpacks
OK I will go that direction providing my own Dockerfile to railway, i'll let you know, thanks for your fast responses
ok using the multi-staged Dockerfile does build and run locally, however on railway did in fact detect Dockerfile as build setting automatically but it fails to build with the following errors. Is a little bit hard to understand what's going on, the package.json file does exist on the repo trying to be deployed
i can't share this repo unfortunately, maybe i could prepare a minimal test repo with similar setup just simpler
send the dockerfile
attached. is the same one explained here https://www.tomray.dev/nestjs-docker-production
which works out of the box for any default NestJS setup created with nest cli
and
.dockerignore
this issue looks like its from the deployment logs? why do you need the package.json during the deployment?
and if you do, just copy it into the final stage
yes the logs are from deployment logs, good catch will look into that the package.json shouldn't be needed cause the Dockefile is calling "node" directly not npm start or anything like that. however the service on railway has "npm run start:dev" as configuration, maybe that's the issue, will check if emptying that configuration fixes it
yeah that would definitely do it
now is empty, redeploying..
success 🤩 !
awesome
thanks @Brody for your guidance appreciate it
no problem, happy to help
i'll mark this solved