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
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 sense
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
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 🤩 !
thanks @Brody for your guidance appreciate it
no problem, happy to help
i'll mark this solved

Looking for more? Join the community!

Recommended Posts
SQLite DatabaseIm trying to deplay a discord bot that uses an sqlite database. Ive created a persistent volume for About storageHello I'm newbie here, i just wanted to know how much storage will i have with the hobby plan?, I anode_modulesI'm trying to deploy using my build script. The build script consist in install normally the packageDefault Express template fails to deployHi, I've tried to deploy the ExpressJS template with no modifications, but am getting errors. Thx foQuestions about pricing for my customersHi, I'm planning to open a web agency and use Railway to deploy our customers' websites. Each customRailway IPv4Guys, does Railway "exports" IPv4 to another service allow its usage permission? I'm using a Redis s[PHP] Route all requests to index.phphttps://twitter.com/Shpigford/status/1693092242943025554I can't buy the planWhen I try to subscribe to the $5 plan, it gives me an error message saying "Your card does not suppI have a problem with my express applicationin the application status it says success but it is not displayed on the websitewhat is the reason for this error?npm WARN config production Use `--omit=dev` instead.Subscription already existsI can't enable the developer plan, the system returns the message: "Subscription already exists"FLASK APP failed to deployI used the refernce flask project idk why maybe the build/run command i put in was incorrect?503 error after binding to ipv6I get a 503 error after binding to ipv6 for internal communication between 2 services. attached my How do I link my services internally?Hello, I tried to figure it out on my own, but I have just ended up losing sleep haha. I'm having anBuild fails when pushing a project with docker-compose file.I am trying to link a project from cli and trying to push it to railway. i am using a docker composeQuestionsI have deployed my project. How can I put this project as asleep?my api wont start on railwayi tried remvoing nodemon from my start script and I also tried in my start script using "node index.cant see my domains in settingsI added domains last day and now i cant see and cant see even my generated free domain project id :laravel volume for the image storageHi! I have a Laravel application deployed via Github to a Railway service. The app is using a Localhello, I try to dump my database with MYSQLDUMP but always get an empty document and the following :stderr: /bin/sh: 1: mysqldump: not found @project: 61093780-ada7-48c8-baad-204a654316a2 @environment