在Heroku上成功部署node.js缺少什么

时间:2020-11-09 07:28:14

标签: node.js heroku procfile

我花了很多时间来做与heroku手册中关于node.js部署的完全相同的操作。我正在使用nedb作为数据存储和node.js14.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

Procfile

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

package.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"
  }
}

app.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}/`);
});

0 个答案:

没有答案