首页 > 解决方案 > 为什么这个 node.js 应用程序由 Heroku 在本地运行,但没有在 Heroku 中加载?

问题描述

我第一次尝试使用 Heroku 部署应用程序,在成功提交 repo 并将更改推送到 Heroku 后,应用程序仍然无法加载。

Heroku 日志:

2020 - 03 - 04 T11: 06: 06.898178 + 00: 00 heroku[web .1]: State changed from starting to crashed
2020 - 03 - 04 T11: 06: 06.806047 + 00: 00 app[web .1]: npm ERR!missing script: start
2020 - 03 - 04 T11: 06: 06.820983 + 00: 00 app[web .1]:
  2020 - 03 - 04 T11: 06: 06.821278 + 00: 00 app[web .1]: npm ERR!A complete log of this run can be found in:
  2020 - 03 - 04 T11: 06: 06.821337 + 00: 00 app[web .1]: npm ERR!/app/.npm / _logs / 2020 - 03 - 04 T11_06_06_806Z - debug.log
2020 - 03 - 04 T11: 06: 06.881460 + 00: 00 heroku[web .1]: Process exited with status 1
2020 - 03 - 04 T11: 09: 27.000000 + 00: 00 app[api]: Build started by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 09: 40.461743 + 00: 00 app[api]: Deploy b856e1a0 by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 09: 40.461743 + 00: 00 app[api]: Release v11 created by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 09: 40.921846 + 00: 00 heroku[web .1]: State changed from crashed to starting
2020 - 03 - 04 T11: 09: 40.000000 + 00: 00 app[api]: Build succeeded
2020 - 03 - 04 T11: 09: 43.094952 + 00: 00 heroku[web .1]: Starting process with command `npm start`
2020 - 03 - 04 T11: 09: 45.156685 + 00: 00 heroku[web .1]: State changed from starting to crashed
2020 - 03 - 04 T11: 09: 45.097670 + 00: 00 app[web .1]: npm ERR!missing script: start
2020 - 03 - 04 T11: 09: 45.102936 + 00: 00 app[web .1]:
  2020 - 03 - 04 T11: 09: 45.103180 + 00: 00 app[web .1]: npm ERR!A complete log of this run can be found in:
  2020 - 03 - 04 T11: 09: 45.103338 + 00: 00 app[web .1]: npm ERR!/app/.npm / _logs / 2020 - 03 - 04 T11_09_45_098Z - debug.log
2020 - 03 - 04 T11: 09: 45.139795 + 00: 00 heroku[web .1]: Process exited with status 1
2020 - 03 - 04 T11: 11: 52.000000 + 00: 00 app[api]: Build started by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 12: 05.304994 + 00: 00 heroku[web .1]: State changed from crashed to starting
2020 - 03 - 04 T11: 12: 05.046524 + 00: 00 app[api]: Deploy 44 da3cc6 by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 12: 05.046524 + 00: 00 app[api]: Release v12 created by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 12: 07.607259 + 00: 00 heroku[web .1]: Starting process with command `npm start`
2020 - 03 - 04 T11: 12: 05.000000 + 00: 00 app[api]: Build succeeded
2020 - 03 - 04 T11: 12: 09.990662 + 00: 00 heroku[web .1]: State changed from starting to up
2020 - 03 - 04 T11: 12: 09.637412 + 00: 00 app[web .1]:
  2020 - 03 - 04 T11: 12: 09.637434 + 00: 00 app[web .1]: > airbnb @1 .0 .0 start / app
2020 - 03 - 04 T11: 12: 09.637434 + 00: 00 app[web .1]: > node index.js
2020 - 03 - 04 T11: 12: 09.637435 + 00: 00 app[web .1]:
  2020 - 03 - 04 T11: 12: 09.804031 + 00: 00 app[web .1]: server is running
2020 - 03 - 04 T11: 14: 33.000000 + 00: 00 app[api]: Build started by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 14: 46.829363 + 00: 00 heroku[web .1]: Restarting
2020 - 03 - 04 T11: 14: 46.832814 + 00: 00 heroku[web .1]: State changed from up to starting
2020 - 03 - 04 T11: 14: 46.617874 + 00: 00 app[api]: Deploy ebc34190 by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 14: 46.617874 + 00: 00 app[api]: Release v13 created by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 14: 47.000000 + 00: 00 app[api]: Build succeeded
2020 - 03 - 04 T11: 14: 47.874543 + 00: 00 heroku[web .1]: Stopping all processes with SIGTERM
2020 - 03 - 04 T11: 14: 47.977184 + 00: 00 heroku[web .1]: Process exited with status 143
2020 - 03 - 04 T11: 14: 49.232441 + 00: 00 heroku[web .1]: Starting process with command `node index.js`
2020 - 03 - 04 T11: 14: 51.656608 + 00: 00 heroku[web .1]: State changed from starting to up
2020 - 03 - 04 T11: 14: 51.560969 + 00: 00 app[web .1]: server is running
2020 - 03 - 04 T11: 20: 46.000000 + 00: 00 app[api]: Build started by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 20: 59.379726 + 00: 00 app[api]: Deploy b253d4d4 by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 20: 59.379726 + 00: 00 app[api]: Release v14 created by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 21: 00.304391 + 00: 00 heroku[web .1]: Restarting
2020 - 03 - 04 T11: 21: 00.308413 + 00: 00 heroku[web .1]: State changed from up to starting
2020 - 03 - 04 T11: 20: 59.000000 + 00: 00 app[api]: Build succeeded
2020 - 03 - 04 T11: 21: 01.360046 + 00: 00 heroku[web .1]: Stopping all processes with SIGTERM
2020 - 03 - 04 T11: 21: 01.466415 + 00: 00 heroku[web .1]: Process exited with status 143
2020 - 03 - 04 T11: 21: 03.924313 + 00: 00 heroku[web .1]: Starting process with command `node index.js`
2020 - 03 - 04 T11: 21: 06.294179 + 00: 00 app[web .1]: server is running
2020 - 03 - 04 T11: 21: 07.763819 + 00: 00 heroku[web .1]: State changed from starting to up
2020 - 03 - 04 T11: 30: 52.000000 + 00: 00 app[api]: Build started by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 31: 06.009751 + 00: 00 heroku[web .1]: Restarting
2020 - 03 - 04 T11: 31: 06.013344 + 00: 00 heroku[web .1]: State changed from up to starting
2020 - 03 - 04 T11: 31: 05.790725 + 00: 00 app[api]: Deploy bd9bf403 by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 31: 05.790725 + 00: 00 app[api]: Release v15 created by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 31: 07.206890 + 00: 00 heroku[web .1]: Stopping all processes with SIGTERM
2020 - 03 - 04 T11: 31: 07.283478 + 00: 00 heroku[web .1]: Process exited with status 143
2020 - 03 - 04 T11: 31: 06.000000 + 00: 00 app[api]: Build succeeded
2020 - 03 - 04 T11: 31: 07.922427 + 00: 00 heroku[web .1]: Starting process with command `npm start`
2020 - 03 - 04 T11: 31: 09.697432 + 00: 00 app[web .1]:
  2020 - 03 - 04 T11: 31: 09.697448 + 00: 00 app[web .1]: > airbnb @1 .0 .0 start / app
2020 - 03 - 04 T11: 31: 09.697449 + 00: 00 app[web .1]: > node index.js
2020 - 03 - 04 T11: 31: 09.697449 + 00: 00 app[web .1]:
  2020 - 03 - 04 T11: 31: 09.841347 + 00: 00 app[web .1]: server is running
2020 - 03 - 04 T11: 31: 10.158006 + 00: 00 heroku[web .1]: State changed from starting to up
2020 - 03 - 04 T11: 39: 27.000000 + 00: 00 app[api]: Build started by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 39: 40.313098 + 00: 00 app[api]: Deploy 5 d445be2 by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 39: 40.313098 + 00: 00 app[api]: Release v16 created by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 39: 40.000000 + 00: 00 app[api]: Build succeeded
2020 - 03 - 04 T11: 39: 41.143634 + 00: 00 heroku[web .1]: Restarting
2020 - 03 - 04 T11: 39: 41.161325 + 00: 00 heroku[web .1]: State changed from up to starting
2020 - 03 - 04 T11: 39: 41.887182 + 00: 00 heroku[web .1]: Stopping all processes with SIGTERM
2020 - 03 - 04 T11: 39: 41.956999 + 00: 00 heroku[web .1]: Process exited with status 143
2020 - 03 - 04 T11: 39: 43.484238 + 00: 00 heroku[web .1]: Starting process with command `node index.js`
2020 - 03 - 04 T11: 39: 45.834243 + 00: 00 app[web .1]: server is running
2020 - 03 - 04 T11: 39: 46.339851 + 00: 00 heroku[web .1]: State changed from starting to up
2020 - 03 - 04 T11: 41: 00.000000 + 00: 00 app[api]: Build started by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 41: 13.457898 + 00: 00 heroku[web .1]: Restarting
2020 - 03 - 04 T11: 41: 13.473960 + 00: 00 heroku[web .1]: State changed from up to starting
2020 - 03 - 04 T11: 41: 12.858989 + 00: 00 app[api]: Deploy 7357470 a by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 41: 12.858989 + 00: 00 app[api]: Release v17 created by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 41: 13.000000 + 00: 00 app[api]: Build succeeded
2020 - 03 - 04 T11: 41: 14.845852 + 00: 00 heroku[web .1]: Stopping all processes with SIGTERM
2020 - 03 - 04 T11: 41: 14.948458 + 00: 00 heroku[web .1]: Process exited with status 143
2020 - 03 - 04 T11: 41: 17.987602 + 00: 00 heroku[web .1]: Starting process with command `node index.js`
2020 - 03 - 04 T11: 41: 21.528516 + 00: 00 app[web .1]: server is running
2020 - 03 - 04 T11: 41: 22.657768 + 00: 00 heroku[web .1]: State changed from starting to up
2020 - 03 - 04 T11: 48: 56.000000 + 00: 00 app[api]: Build started by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 49: 10.202399 + 00: 00 heroku[web .1]: Restarting
2020 - 03 - 04 T11: 49: 10.205603 + 00: 00 heroku[web .1]: State changed from up to starting
2020 - 03 - 04 T11: 49: 09.824296 + 00: 00 app[api]: Deploy 9 dbe0b02 by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 49: 09.824296 + 00: 00 app[api]: Release v18 created by user freecorpteam @gmail.com
2020 - 03 - 04 T11: 49: 10.000000 + 00: 00 app[api]: Build succeeded
2020 - 03 - 04 T11: 49: 11.335018 + 00: 00 heroku[web .1]: Stopping all processes with SIGTERM
2020 - 03 - 04 T11: 49: 11.464510 + 00: 00 heroku[web .1]: Process exited with status 143
2020 - 03 - 04 T11: 49: 11.944025 + 00: 00 heroku[web .1]: Starting process with command `node index.js`
2020 - 03 - 04 T11: 49: 13.650108 + 00: 00 heroku[web .1]: State changed from starting to up
2020 - 03 - 04 T11: 49: 13.488186 + 00: 00 app[web .1]: server is running

index.js

const bodyParser = require('body-parser'),
	express = require('express'),
	app = express();

// Setting up the app
app.use(express.static('public'));
app.set('view engine', 'ejs');

// ================= Display routes ==================

// === Root route ===

app.get('/', function(req, res) {
	res.render('home');
});

app.get('/blog', function(req, res) {
	res.render('blog');
});

app.listen(process.env.PORT, function() {
	console.log('server is running');
});

包.json

{
	"name": "airbnb",
	"version": "1.0.0",
	"description": "Airbnb guide",
	"main": "index.js",
	"scripts": {
		"test": "echo \"Error: no test specified\" && exit 1",
		"start": "node index.js"
	},
	"author": "Freedom Corporation",
	"license": "ISC",
	"dependencies": {
		"ejs": "^3.0.1",
		"express": "^4.17.1"
	}
}

档案

web: node index.js

该应用程序在本地运行良好,我尝试多次添加启动脚本并多次重新初始化 npm。

谢谢,

标签: node.jsexpressheroku

解决方案


推荐阅读