Davide Ferrero
Davide Ferrero

Reputation: 185

Deploying a NestJs project on a single board computer (Raspberry or similar)

even if it seems a simple task I'm having some trouble finding a solution. I know that with Nest CLI I can use the command "nest build" in order to create a dist folder that contains the production files of my project.

The problem is when I move the folder on my Raspberry and i try to run the project with the command "node dist/main" following NestJs instructions. Nothing starts because node says that it cannot find @nestjs/core and other modules.

I did't find nothing clear in the official guide about deploying the app, so my question is: what do I need to move onto my rasperry in addition to dist folder? Do I need to reinstall all node_modules folder or it's possible to have a running project without have to reinstall 800Mb of modules?

Upvotes: 0

Views: 535

Answers (1)

lafusew
lafusew

Reputation: 171

Yes you need to run yarn or npm install on your production environment, as your dist folder only contains your own code.

Because unlike compiled language like Golang where all dependencies are bundled and compiled in you executable file, Javascript bundlers don't. Your bundled code in dist still contains require or import statement to get dependencies from node_modules.

You can also run npm prune --production to remove any developpement dependencies and thus reduce the size of your node_modules folder. (I believe that yarn does it by default.)

Upvotes: 1

Related Questions