R
Railway•15mo ago
dciccale

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 details
19 Replies
Percy
Percy•15mo ago
Project ID: N/A
Brody
Brody•15mo ago
developer dependencies that are required to build the app should not be in developer dependencies
dciccale
dciccale•15mo ago
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 sense
Brody
Brody•15mo ago
the 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
dciccale
dciccale•15mo ago
OK I will go that direction providing my own Dockerfile to railway, i'll let you know, thanks for your fast responses
dciccale
dciccale•15mo ago
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
dciccale
dciccale•15mo ago
i can't share this repo unfortunately, maybe i could prepare a minimal test repo with similar setup just simpler
Brody
Brody•15mo ago
send the dockerfile
dciccale
dciccale•15mo ago
attached. is the same one explained here https://www.tomray.dev/nestjs-docker-production
dciccale
dciccale•15mo ago
which works out of the box for any default NestJS setup created with nest cli and .dockerignore
Dockerfile
.dockerignore
node_modules
npm-debug.log
dist
Dockerfile
.dockerignore
node_modules
npm-debug.log
dist
Brody
Brody•15mo ago
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
dciccale
dciccale•15mo ago
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
Brody
Brody•15mo ago
yeah that would definitely do it
dciccale
dciccale•15mo ago
now is empty, redeploying..
dciccale
dciccale•15mo ago
success 🤩 !
Brody
Brody•15mo ago
awesome
dciccale
dciccale•15mo ago
thanks @Brody for your guidance appreciate it
Brody
Brody•15mo ago
no problem, happy to help
dciccale
dciccale•15mo ago
i'll mark this solved
Want results from more Discord servers?
Add your server