Code Monkey home page Code Monkey logo

Comments (4)

Saluki avatar Saluki commented on June 7, 2024 3

Hello @nodejsdeveloperskh,

The new Dockerfile is now on the master branch & everything is working fine - thanks for the contribution.

from nestjs-template.

Saluki avatar Saluki commented on June 7, 2024

Hi @nodejsdeveloperskh 👋

The major difference between the 2 calls to npm ci is located in the NODE_ENV environment variable. This variable tells NPM if the command is launched in a production environment or not. In the first Docker stage (the build stage) our NODE_ENV variable is set to build (it could also be set to develop or testing) and the npm ci will therefore install all dependencies - even the development dependencies. This is essentiel because we need to build the TypeScript code and require the presence of development dependencies.

In the second stage (which will be our final Docker image) we have moved the Node.js code in the image and require only the production dependencies. We therefore set the NODE_ENV to production and npm ci will only install the production dependencies. This ensures that we only have the required Node.js components in the final Docker image.

I hope this answers your question 👍

from nestjs-template.

kasir-barati avatar kasir-barati commented on June 7, 2024

@Saluki Thanks for the reply. Yup, I am inattention to the details. but I think you could do it simpler by npm prune --production in the second stage. after that you could copy the node_modules like the dist directory. unless you use the different base images in the stages.

from nestjs-template.

Saluki avatar Saluki commented on June 7, 2024

This is indeed an excellent proposal, I didn't know npm prune could target production dependencies only. I will reopen the issue since it may be an interesting Docker build optimization.

from nestjs-template.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.