gpt4 book ai didi

node.js - Nest.JS 部署到 Heroku

转载 作者:搜寻专家 更新时间:2023-10-31 23:23:06 25 4
gpt4 key购买 nike

我目前正在尝试部署由 Nest.JS CLI(从版本 5.3.0 开始)生成的基本入门模板,并且似乎在应用程序启动时超时。我想知道是否有人成功部署到 Heroku?

我不确定是否需要包含某种 Procfile?

此外,关于部署 Nest.JS 的信息似乎不多

我尝试部署时的 Heroku 日志。

heroku[web.1]: Starting process with command `npm start`
app[web.1]:
app[web.1]: > testy@0.0.0 start /app
app[web.1]: > ts-node -r tsconfig-paths/register src/main.ts
app[web.1]:
app[web.1]: [Nest] 21 - 2018-10-16 06:52:17 [NestFactory] Starting Nest application...
app[web.1]: [Nest] 21 - 2018-10-16 06:52:17 [InstanceLoader] AppModule dependencies initialized +21ms
app[web.1]: [Nest] 21 - 2018-10-16 06:52:17 [RoutesResolver] AppController {/}: +48ms
app[web.1]: [Nest] 21 - 2018-10-16 06:52:17 [RouterExplorer] Mapped {/, GET} route +7ms
app[web.1]: [Nest] 21 - 2018-10-16 06:52:17 [NestApplication] Nest application successfully started +3ms
app[web.1]: Error waiting for process to terminate: No child processes
heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
heroku[web.1]: Stopping process with SIGKILL
heroku[web.1]: Process exited with status 22
heroku[web.1]: State changed from starting to crashed
heroku[web.1]: State changed from crashed to starting

我的 package.json 文件在下面...

{
"name": "testy",
"version": "0.0.0",
"description": "description",
"author": "",
"license": "MIT",
"scripts": {
"format": "prettier --write \"src/**/*.ts\"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "nodemon",
"start:debug": "nodemon --config nodemon-debug.json",
"prestart:prod": "rimraf dist && tsc",
"start:prod": "node dist/main.js",
"start:hmr": "node dist/server",
"lint": "tslint -p tsconfig.json -c tslint.json",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:e2e": "jest --config ./test/jest-e2e.json",
"webpack": "webpack --config webpack.config.js"
},
"dependencies": {
"@nestjs/common": "^5.1.0",
"@nestjs/core": "^5.1.0",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.2.2",
"typescript": "^3.0.1"
},
"devDependencies": {
"@nestjs/testing": "^5.1.0",
"@types/express": "^4.16.0",
"@types/jest": "^23.3.1",
"@types/node": "^10.7.1",
"@types/supertest": "^2.0.5",
"jest": "^23.5.0",
"nodemon": "^1.18.3",
"prettier": "^1.14.2",
"rimraf": "^2.6.2",
"supertest": "^3.1.0",
"ts-jest": "^23.1.3",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.5.0",
"tslint": "5.11.0",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0",
"webpack-node-externals": "^1.7.2"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}

如果有人在部署此堆栈方面有任何经验,很高兴收到您的来信

最佳答案

Heroku默认给你分配了一个端口,并将端口添加到环境变量(env)中,所以你可以将端口设置为一个固定的数字,你需要将你的主文件更改为:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(process.env.PORT || 3000);
}
bootstrap();

关于node.js - Nest.JS 部署到 Heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52829683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com