DEV Community

Cover image for Setting up a NestJS project with Docker for Back-End development

Setting up a NestJS project with Docker for Back-End development

Erez Hod on January 31, 2021

NestJS has been my go-to Back-End framework for API development in NodeJS for quite a while now after discovering how annoying it can be to set up ...
Collapse
 
yuvalhazaz profile image
Yuval Hazaz •

Nicely done!
We created an open-source project that let you create a full functional NestJS backend with GraphQL and REAT API over your custom model in minutes. We generate a high quality TypeScript code and let you continue development on your own.
You are invited to try it on
app.amplication.com

The repo is in github.com/amplication/amplication

Collapse
 
erezhod profile image
Erez Hod •

Looks promising! Will look into it 🙂

Collapse
 
manhhailua profile image
Mạnh Phạm •

Nice post!
But production stage better not have COPY . .

Collapse
 
junibrosas profile image
Juni Brosas •

Got my project dockerized, thank you!

Collapse
 
dewaldels profile image
Dewald Els •

Nice work! Got it working first try thanks to the clear instructions!

Collapse
 
odairto profile image
odairto •

Thank you!!! Nice article!! Works perfectly!

Collapse
 
eybel profile image
Abel Simon •

I have a doubt. If I only run "docker-compose up prod" I dont have a '/dist' folder by then so why would you use "COPY --from=development /app/dist ./dist" ? Why dont we have a RUN npm build in the production target? If these are like 2 different images, why are depending on development dist folder, or the whole process takes place when built? Im somehow confused there

Collapse
 
ygrek09396626 profile image
ygrek •

Hi, nice article. One important note: in the production stage of Dockerfile there should not be a COPY . . command. On prod we just need to start the app from the dist folder and having all sources in the image is at least not necessary.

Collapse
 
dsky profile image
Dmitry •

One a day I shown NestJS to Angular team and they built MVP and production ready beta in a couple weeks like they always knew how to cook a great API.

GraphQL, tests and docs out of the box. Great tool 👍🏼

Collapse
 
erezhod profile image
Erez Hod •

NestJS is golden for Angular developers who want/need to go Full-Stack. The syntax and workflow is so similar, which makes it seamless to move between the two. Great choice and recommendation 👍👍👍

Collapse
 
truezombie profile image
Oleg Ovcharenko • • Edited

Hi Erez Hod. Nice article. Could you please explain how better works with node_modules in your configuration? I mean we have no node_modules with this configuration. But we need it for vscode for (development process linter, prettier, etc), and also what I need to do if I need to install an additional npm package?

Do we need to install node_modules also through npm install (by locally) for vscode (development process linter, prettier, etc)? And for installation of additional node_module, we need to stop docker-compose, install additional node_module and after that run docker like docker-compose up --build -V for rebuilding node_modules in our volume. Is it correct?

Collapse
 
aliweb profile image
AliWeb •

Thank you.

what about the deployment?
I am new to nestjs. Would you please explain what to do next to make it fully work on the server?

Collapse
 
vjnvisakh profile image
Visakh Vijayan •

nice read. How to add a postgres db to start along with nestjs app out of the box

Collapse
 
codefalcon95 profile image
codefalcon95 •

Hello, i tried this example and the prod version didnt start up always giving Error: Cannot find module '/usr/src/app/dist/main'.

Collapse
 
erezhod profile image
Erez Hod •

Hi 🙂
How is your docker-compose.yml defined? also, does your app run using npm run start:prod without Docker?

Collapse
 
ahmedyounes profile image
Ahmed Younes •

service refers to undefined network nestjs-network: invalid compose project