TypeORM和PM2:无法在Heroku上运行应用

时间:2018-06-25 05:52:00

标签: node.js heroku typeorm

我有一个使用typeorm构建的应用程序,我打算使用heroku托管应用程序,该应用程序可以在localhost上完美运行,但是当我部署到Heroky时,出现错误Quota Exceeded。我已经尝试了整整一天的工作,但无济于事。

下面是我的Procfile中的内容

 ./node_modules/.bin/pm2-runtime start src/index.ts  --name API-Server -i max

下面是我拥有的典型类型实体的示例

从“ typeorm”导入{Entity,PrimaryGeneratedColumn,Column,CreateDateColumn,UpdateDateColumn,ManyToOne};

@Entity()
export class Tag {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({ nullable: false })
    name: string
}

以下是heroku错误日志

2018-06-25T06:05:30.606404+00:00 heroku[web.1]: Process running mem=931M(181.9%)
2018-06-25T06:05:30.606527+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2018-06-25T06:05:37.081653+00:00 heroku[web.1]: Process running mem=1279M(249.9%)
2018-06-25T06:05:37.081887+00:00 heroku[web.1]: Error R15 (Memory quota vastly exceeded)
2018-06-25T06:05:37.081887+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-06-25T06:05:37.311449+00:00 heroku[web.1]: Process exited with status 137
2018-06-25T06:05:37.324274+00:00 heroku[web.1]: State changed from starting to crashed

这是我的package.json

{
   "name": "Api Server",
   "version": "0.0.1",
   "description": "Api Server",
   "devDependencies": {
      "@types/bcrypt": "^1.0.0",
      "@types/express": "^4.11.1",
      "@types/moment": "^2.13.0",
      "@types/multer": "^1.3.6",
      "@types/multiparty": "0.0.31",
      "@types/node": "^8.0.29",
      "@types/raven": "^2.1.6",
      "@types/socket.io": "^1.4.33",
      "nodemon": "^1.17.3",
      "ts-node": "3.3.0",
      "typescript": "2.5.2"
   },
   "dependencies": {
      "@types/jsonwebtoken": "^7.2.6",
      "apidoc": "^0.17.6",
      "async": "^2.6.1",
      "aws-sdk": "^2.221.1",
      "bcrypt": "^2.0.0",
      "bluebird": "^3.5.1",
      "body-parser": "^1.18.2",
      "cors": "^2.8.4",
      "cron": "^1.3.0",
      "dotenv": "^5.0.1",
      "express": "^4.16.3",
      "google-spreadsheet": "^2.0.4",
      "googleapis": "^28.0.1",
      "jsonwebtoken": "^8.2.0",
      "knex": "^0.14.6",
      "lodash": "^4.17.5",
      "moment": "^2.22.0",
      "morgan": "^1.9.0",
      "multer": "^1.3.0",
      "mysql": "^2.14.1",
      "pm2": "^2.10.4",
      "raven": "^2.4.2",
      "reflect-metadata": "^0.1.10",
      "rethinkdb": "^2.3.3",
      "socket.io": "^2.1.0",
      "typeorm": "0.2.2"
   },
   "scripts": {
      "start": "ts-node src/index.ts  --name API-Server",
      "heroku-postbuild": "./setup.sh && ./node_modules/.bin/pm2 install typescript",
      "watch": "nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec 'ts-node' src/index.ts"
   }
}

1 个答案:

答案 0 :(得分:0)

根据最佳做法(https://devcenter.heroku.com/articles/node-best-practices#avoid-garbage),您可以将节点容器限制在Procfile中:

web: node --optimize_for_size --max_old_space_size=460 --gc_interval=100 server.js

重复吗? https://stackoverflow.com/a/55553030/3969007