首页 > 解决方案 > 在 Heroku 上成功部署我的 node.js 缺少什么

问题描述

我花了很多时间来做与 heroku 手册中的 node.js 部署完全相同的事情。我使用 nedb 作为数据存储和 node.js 14.x。其中之一是问题吗?没有进一步的计划它可能是什么。

heroku日志

2020-11-09T07:11:42.803302+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2020-11-09T07:11:42.803322+00:00 app[web.1]: designed for a production environment, as it will leak
2020-11-09T07:11:42.803323+00:00 app[web.1]: memory, and will not scale past a single process.
2020-11-09T07:11:42.812099+00:00 app[web.1]: Server running at http://localhost:49728/
2020-11-09T07:12:40.832978+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-11-09T07:12:40.849869+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-11-09T07:12:40.929805+00:00 heroku[web.1]: Process exited with status 137
2020-11-09T07:12:40.964808+00:00 heroku[web.1]: State changed from starting to crashed

档案

"scripts": {
  "start": "node app.js"
}

包.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "Demo",
  "main": "app.js",
  "scripts": {
    "start": "node app.js",
  },
  "type": "module",
  "engines": {
    "node": "14.x"
  },
  "dependencies": {
    "body-parser": "^1.19.0",
    "express": "^4.17.1",
    "express-session": "^1.17.1",
    "hbs": "^2.9.0",
    "method-override": "^3.0.0",
    "nedb": "^1.8.0",
    "nedb-promise": "^2.0.1",
    "nedb-promises-ts": "0.0.1-4",
    "prettier": "^2.1.2",
    "typescript": "^4.0.3"
  },
  "devDependencies": {
    "@types/express": "^4.17.8",
    "@types/nedb": "^1.8.11",
    "@types/node": "^14.14.2",
    "@typescript-eslint/eslint-plugin": "^4.4.1",
    "@typescript-eslint/parser": "^4.4.1",
    "eslint": "^7.11.0",
    "eslint-config-prettier": "^6.13.0"
  }
}

应用程序.js

import express from "express";

import { indexRoutes } from "./routes/indexRoutes.js";
...
const app = express();
...

app.use("/", indexRoutes);
...
const hostname = "localhost";
const port = process.env.PORT || 3000;
app.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

标签: node.jsherokuprocfile

解决方案


推荐阅读