应用程序中出现错误,无法为页面提供服务.将Node.Js REST部署到heroku



我是使用Heroku部署REST api的新手。我已经在Node.JS中编写了一个REST api,现在我想将其部署到Heroku。请问有没有循序渐进的方法

我在Heroku上得到这个错误

Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail

在我的桌面,测试邮差它工作得很好。但是我不能从浏览器中查看

https://test-restapi2.herokuapp.com/employees

我的Node.Js应用程序是这样的:

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mysql = require('mysql');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended:true
}));
app.get('/',function(req , res){
return res.send({error: true,message: 'hello'})
});
var dbConn = mysql.createConnection({
host: 'xxxxxxxxxxxxxxxx',
user: 'xxxxxxxxxxxxxx',
password: 'xxxxxxxxxxx',
database: 'xxxxxxxxxxxxxxxxx'
});
dbConn.connect();
app.get('/employees',function(req,res){
dbConn.query('SELECT * FROM employeedb',function(error, results, fields){
if (error) throw error;
return res.send({ error: false, data: results, message: 'users list' });
});
});

app.listen(5000,function(){
console.log('App running on port 5000');
});
module.exports = app;

请问我怎样才能解决这个问题?

编辑

检查日志,我看到了这个:

2021-10-09T19:28:55.666772+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-09T19:28:57.813040+00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-09T19:28:59.202356+00:00 app[web.1]: npm ERR! missing script: start
2021-10-09T19:28:59.208564+00:00 app[web.1]: 
2021-10-09T19:28:59.208837+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-09T19:28:59.208892+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-10-09T19_28_59_202Z-debug.log
2021-10-09T19:28:59.327035+00:00 heroku[web.1]: Process exited with status 1
2021-10-09T19:28:59.422562+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-09T19:29:04.931511+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=test-restapi2.herokuapp.com request_id=aafd0e0b-988e-4673-9359-f7576e340d75 fwd="154.120.87.9" dyno= connect= service= status=503 bytes= protocol=https
2021-10-09T19:29:06.103970+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=test-restapi2.herokuapp.com request_id=6b375048-c8db-4323-8484-ba60aafea022 fwd="154.120.87.9" dyno= connect= service= status=503 bytes= protocol=https
2021-10-09T19:32:15.776019+00:00 app[api]: Starting process with command `npm start` by user emeka1987ng@gmail.com
2021-10-09T19:32:17.857845+00:00 heroku[run.9636]: Awaiting client
2021-10-09T19:32:17.890327+00:00 heroku[run.9636]: Starting process with command `npm start`
2021-10-09T19:32:17.959936+00:00 heroku[run.9636]: State changed from starting to up
2021-10-09T19:32:21.444257+00:00 heroku[run.9636]: Process exited with status 1
2021-10-09T19:32:21.499239+00:00 heroku[run.9636]: State changed from up to complete
2021-10-09T19:32:28.775794+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/employees" host=test-restapi2.herokuapp.com request_id=1a03731f-41cb-438d-b877-c1e49d5dd039 fwd="107.155.108.143" dyno= connect= service= status=503 bytes= protocol=https
2021-10-09T19:32:39.195421+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/employees" host=test-restapi2.herokuapp.com request_id=c1833124-6596-4401-a765-f8a65345b5e1 fwd="52.204.27.85" dyno= connect= service= status=503 bytes= protocol=https

您可以查看应用程序的日志并确定问题所在。

在项目页面的右上角,有一个"更多"按钮。点击这里,然后点击"查看日志"你应该能够看到确切的问题并解决它。

相关内容

  • 没有找到相关文章

最新更新