簡體   English   中英

我正在嘗試使用 heroku 部署一個簡單的 nodejs 應用程序,它已成功部署,但在打開 url 時出錯?

[英]I am trying to deploy a simple nodejs app using heroku and its is deployed successfully but giving error on opening the url?

假設部署過程中出現錯誤,我錯誤地使用同一個 repo 部署了兩個應用程序,從未使用 heroku 部署任何應用程序,所以請查看我的問題

我的 index.js

const express = require("express");
const port = process.env.port || 3000;
const path = require("path");

var app = express();
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));

//using middleware to include static files like css and javascript
app.use(express.static("static"));
app.get("/", (req, res) => {
  return res.render("index");
});

app.listen(port, (err) => {
  if (err) {
    console.log("Error found");
    return res.send("Error");
  }
  console.log("Server running on port: ", port);
});

我的 package.json

{
  "name": "resume_project",
  "version": "1.0.0",
  "description": "**It is a dynamic website containg a resume template to showcase, it has details like my profile ids, some of the projects, Education etc.**",
  "main": "\u001b[A\u001b[A\u001b[Bdhruv singhal\u001b[B\u001b[D\u001b[D\u001b[A\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[\u001b[B",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon index.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/dhruv354/resume_project.git"
  },
  "author": "dhruv singhal",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/dhruv354/resume_project/issues"
  },
  "homepage": "https://github.com/dhruv354/resume_project#readme",
  "dependencies": {
    "ejs": "^3.1.6",
    "express": "^4.17.1"
  }
}

heroku 日志 --tail

 »   Warning: heroku update available from 7.53.0 to 7.53.1.
2021-05-17T11:07:25.647982+00:00 app[api]: Release v1 created by user dhruv.singhal2612@gmail.com
2021-05-17T11:07:25.647982+00:00 app[api]: Initial release by user dhruv.singhal2612@gmail.com
2021-05-17T11:07:26.025509+00:00 app[api]: Enable Logplex by user dhruv.singhal2612@gmail.com
2021-05-17T11:07:26.025509+00:00 app[api]: Release v2 created by user dhruv.singhal2612@gmail.com
2021-05-17T11:08:39.000000+00:00 app[api]: Build started by user dhruv.singhal2612@gmail.com
2021-05-17T11:08:54.990971+00:00 app[api]: Deploy dcaa0bec by user dhruv.singhal2612@gmail.com
2021-05-17T11:08:54.990971+00:00 app[api]: Release v3 created by user dhruv.singhal2612@gmail.com
2021-05-17T11:08:55.000000+00:00 app[api]: Build succeeded
2021-05-17T11:08:55.003479+00:00 app[api]: Scaled to web@1:Free by user dhruv.singhal2612@gmail.com
2021-05-17T11:08:58.272953+00:00 heroku[web.1]: Starting process with command `npm start`
2021-05-17T11:09:00.649752+00:00 app[web.1]: npm ERR! missing script: start
2021-05-17T11:09:00.658516+00:00 app[web.1]: 
2021-05-17T11:09:00.658834+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-05-17T11:09:00.658987+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-05-17T11_09_00_650Z-debug.log
2021-05-17T11:09:00.715950+00:00 heroku[web.1]: Process exited with status 1
2021-05-17T11:09:00.804781+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-17T11:09:00.826182+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-17T11:09:03.431232+00:00 heroku[web.1]: Starting process with command `npm start`
2021-05-17T11:09:06.521982+00:00 app[web.1]: npm ERR! missing script: start
2021-05-17T11:09:06.531997+00:00 app[web.1]:
2021-05-17T11:09:06.532511+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-05-17T11:09:06.532702+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-05-17T11_09_06_522Z-debug.log
2021-05-17T11:09:06.591767+00:00 heroku[web.1]: Process exited with status 1
2021-05-17T11:09:06.651080+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-17T11:10:08.000000+00:00 app[api]: Build started by user dhruv.singhal2612@gmail.com
2021-05-17T11:10:30.883151+00:00 app[api]: Deploy 6174a3f9 by user dhruv.singhal2612@gmail.com
2021-05-17T11:10:30.883151+00:00 app[api]: Release v4 created by user dhruv.singhal2612@gmail.com
2021-05-17T11:10:31.000000+00:00 app[api]: Build succeeded
2021-05-17T11:10:31.081243+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-17T11:10:34.558759+00:00 heroku[web.1]: Starting process with command `npm start`
2021-05-17T11:10:38.058050+00:00 app[web.1]:
2021-05-17T11:10:38.058089+00:00 app[web.1]: > resume_project@1.0.0 start /app
2021-05-17T11:10:38.058090+00:00 app[web.1]: > nodemon index.js
2021-05-17T11:10:38.058091+00:00 app[web.1]:
2021-05-17T11:10:38.359100+00:00 app[web.1]: [nodemon] 2.0.7
2021-05-17T11:10:38.360054+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2021-05-17T11:10:38.360505+00:00 app[web.1]: [nodemon] watching path(s): *.*
2021-05-17T11:10:38.360612+00:00 app[web.1]: [nodemon] watching extensions: js,mjs,json
2021-05-17T11:10:38.361510+00:00 app[web.1]: [nodemon] starting `node index.js`
2021-05-17T11:10:38.611086+00:00 app[web.1]: Server running on port:  3000
2021-05-17T11:11:34.662337+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-05-17T11:11:34.720677+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-05-17T11:11:34.852653+00:00 heroku[web.1]: Process exited with status 137
2021-05-17T11:11:34.981104+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-17T11:11:36.282468+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=resume-app-dhruv.herokuapp.com request_id=45a83bd8-8665-4e79-b3d2-1b65084534ef fwd="49.34.85.157" dyno= connect= service= status=503 bytes= protocol=https
2021-05-17T11:11:36.584581+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=resume-app-dhruv.herokuapp.com request_id=71aab104-e585-4b9c-b86e-3edbc11365f0 fwd="49.34.85.157" dyno= connect= service= status=503 bytes= protocol=https
2021-05-17T11:11:38.454567+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=resume-app-dhruv.herokuapp.com request_id=cbaded28-9e12-4eb1-8900-2be54e211247 fwd="49.34.85.157" dyno= connect= service= status=503 bytes= protocol=https
2021-05-17T11:12:08.266884+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=resume-app-dhruv.herokuapp.com request_id=e3777d79-c435-443b-9529-95aece6d8c0f fwd="49.34.85.157" dyno= connect= service= status=503 bytes= protocol=https
2021-05-17T11:12:09.396478+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=resume-app-dhruv.herokuapp.com request_id=7a1adc3a-c8cf-4ecf-8afd-a729192e8fda fwd="49.34.85.157" dyno= connect= service= status=503 bytes= protocol=https
2021-05-17T11:14:53.639282+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=resume-app-dhruv.herokuapp.com request_id=73d769ed-89c4-41dc-9349-62e8be14f6c2 fwd="49.34.85.157" dyno= connect= service= status=503 bytes= protocol=https
2021-05-17T11:14:54.202559+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=resume-app-dhruv.herokuapp.com request_id=43d08929-28aa-4b5e-9f7c-cfb569c1921f fwd="49.34.85.157" dyno= connect= service= status=503 bytes= protocol=https
2021-05-17T12:12:37.458250+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=resume-app-dhruv.herokuapp.com request_id=c2f29684-ed66-4782-8f99-096ccb4ac74d fwd="49.34.85.157" dyno= connect= service= status=503 bytes= protocol=https
2021-05-17T12:12:38.779459+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=resume-app-dhruv.herokuapp.com request_id=25e82ee8-cb94-4c52-bcfa-5d9c1854e496 fwd="49.34.85.157" dyno= connect= service= status=503 bytes= protocol=https

嘗試了其他解決方案但無法解決問題,我無法理解整個問題所在

將啟動腳本更改為

"start": "node index.js"

Nodemon 在開發過程中使用,它甚至不依賴於您的依賴項

也嘗試改變

process.env.port

process.env.PORT

通常 heroku 不想運行任何你喜歡的端口

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM