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