简体   繁体   中英

Deploying Node Application

I am using NestJS and IIS, and I have deployed my dist folder on server through IIS with the help of IISNode , but when I run it, it gives me an error of 'module not found @nestjs/core' etc, so I installed entire package.json files (node_module) on server, after this it start working fine. But I have a question. Do we have to keep node_modules folder on the server which is of 250MB+? Do we have any other alternative by which dist will contain all the required code of node_modules just like an Angular application?

This is not NestJS related, but it is related to NodeJS itself. A typical package.json file looks like this:

{
  "name": "nest-typescript-starter",
  "version": "1.0.0",
  "description": "Nest TypeScript starter repository",
  "license": "MIT",
  "scripts": {
    // ...
  },
  "dependencies": {
    "@nestjs/common": "8.2.3",
    // ...
  },
  "devDependencies": {
    "@nestjs/cli": "8.1.7",
    // ...
  }
}

Everything under dependencies are required at runtime, since they're being used by your application. Anything under devDependencies are only required during development, for various reasons.

It is common to have devDependencies like type modules, testing tools, and others.

While installing a new dependency, you have two options:

# Option 1
npm install <dependency name>

# Option 2
npm install --save-dev <dependency name>

If you provide the --save-dev flag you would install that dependency under devDependencies .

After making your package.json file organized, separating devDependencies from dependencies you can deploy your application properly. During the deployment process, instead of running npm install you can use:

npm install --omit=dev

By doing so, you would only install runtime dependencies to your node_modules .

Finally, you can copy that node_modules to your container (or whatever you're using to deploy) and ship the application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM