Как исправить (throw er; // необработанное событие 'error') ошибку (heroku, nodejs, mysql используется) - PullRequest
0 голосов
/ 30 апреля 2020

Я прочитал несколько вопросов в Stack Overflow и в Google, но он не работает

  1. проверьте, является ли это дублирующим портом
  2. Проверьте, включены ли серверы с несколькими узлами
  3. проверил npm версию

Но это слишком сложно решить, оставив вопрос

var express = require('express')
var app = express()
var bodyParser = require('body-parser')
var router = require('./router/index')

port = process.env.PORT || 7987;

app.listen(port, function() {
    console.log("Open server!!");
});

app.use(express.static('public'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended:true}))
app.set('view engine', 'ejs')

app.use(router)

это мое приложение. js код

{
  "name": "nodeserver",
  "version": "1.0.0",
  "description": "nodeserver test",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.19.0",
    "ejs": "^3.1.2",
    "express": "^4.17.1",
    "mysql": "^2.18.1",
    "nodemon": "^2.0.3",
    "router": "^1.3.5"
  }
}

пакет. json код

2020-04-30T18:51:44.617695+00:00 app[web.1]: > nodeserver@1.0.0 start /app
2020-04-30T18:51:44.617695+00:00 app[web.1]: > node app.js
2020-04-30T18:51:44.617695+00:00 app[web.1]:
2020-04-30T18:51:44.840619+00:00 app[web.1]: Open server
2020-04-30T18:51:45.357941+00:00 heroku[web.1]: State changed from starting to up
2020-04-30T18:52:39.243430+00:00 heroku[web.1]: Restarting
2020-04-30T18:52:39.257169+00:00 heroku[web.1]: State changed from up to starting
2020-04-30T18:52:45.141155+00:00 app[web.1]:
2020-04-30T18:52:45.141170+00:00 app[web.1]: > nodeserver@1.0.0 start /app
2020-04-30T18:52:45.141170+00:00 app[web.1]: > node app.js
2020-04-30T18:52:45.141171+00:00 app[web.1]:
2020-04-30T18:52:45.414948+00:00 app[web.1]: Open server!!
2020-04-30T18:52:46.538075+00:00 heroku[web.1]: State changed from starting to up
2020-04-30T18:53:32.146358+00:00 heroku[router]: at=info method=GET path="/" host=i-tub.herokuapp.com request_id=5d76726b-f6ed-4312-9adf-12a2a853a1f6 fwd="220.80.86.96" dyno=web.1 connect=0ms service=21ms status=200 bytes=1856 protocol=http
2020-04-30T18:53:32.135072+00:00 app[web.1]: indexjs / path loaded
2020-04-30T18:53:44.661353+00:00 app[web.1]: events.js:287
2020-04-30T18:53:44.661365+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-04-30T18:53:44.661365+00:00 app[web.1]: ^
2020-04-30T18:53:44.661366+00:00 app[web.1]:
2020-04-30T18:53:44.661367+00:00 app[web.1]: Error: Connection lost: The server closed the connection.
2020-04-30T18:53:44.661368+00:00 app[web.1]: at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:112:13)
2020-04-30T18:53:44.661368+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:94:28)
2020-04-30T18:53:44.661369+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:526:10)
2020-04-30T18:53:44.661369+00:00 app[web.1]: at Socket.emit (events.js:322:22)
2020-04-30T18:53:44.661370+00:00 app[web.1]: at endReadableNT (_stream_readable.js:1187:12)
2020-04-30T18:53:44.661370+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21)
2020-04-30T18:53:44.661371+00:00 app[web.1]: Emitted 'error' event on Connection instance at:
2020-04-30T18:53:44.661371+00:00 app[web.1]: at Connection._handleProtocolError (/app/node_modules/mysql/lib/Connection.js:423:8)
2020-04-30T18:53:44.661372+00:00 app[web.1]: at Protocol.emit (events.js:310:20)
2020-04-30T18:53:44.661372+00:00 app[web.1]: at Protocol._delegateError (/app/node_modules/mysql/lib/protocol/Protocol.js:398:10)
2020-04-30T18:53:44.661373+00:00 app[web.1]: at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:116:8)
2020-04-30T18:53:44.661373+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:94:28)
2020-04-30T18:53:44.661373+00:00 app[web.1]: [... lines matching original stack trace ...]
2020-04-30T18:53:44.661374+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-04-30T18:53:44.661374+00:00 app[web.1]: fatal: true,
2020-04-30T18:53:44.661375+00:00 app[web.1]: code: 'PROTOCOL_CONNECTION_LOST'
2020-04-30T18:53:44.661375+00:00 app[web.1]: }
2020-04-30T18:53:44.679709+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-04-30T18:53:44.681065+00:00 app[web.1]: npm ERR! errno 1
2020-04-30T18:53:44.686133+00:00 app[web.1]: npm ERR! nodeserver@1.0.0 start: `node app.js`
2020-04-30T18:53:44.686778+00:00 app[web.1]: npm ERR! Exit status 1
2020-04-30T18:53:44.687606+00:00 app[web.1]: npm ERR!
2020-04-30T18:53:44.688059+00:00 app[web.1]: npm ERR! Failed at the nodeserver@1.0.0 start script.
2020-04-30T18:53:44.688882+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-04-30T18:53:44.705921+00:00 app[web.1]:
2020-04-30T18:53:44.706492+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-04-30T18:53:44.706743+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-04-30T18_53_44_690Z-debug.log
2020-04-30T18:53:44.799665+00:00 heroku[web.1]: State changed from up to crashed

это журналы ошибок

После запуска в течение нескольких секунд я ничего не делал, но он внезапно завершил работу

мучаясь несколько дней, оставляю вопрос и прошу помощи

...