我正在https://www.taniarascia.com/node-express-postgresql-heroku/上找到一个nodejs api它使用postgresql,所以它需要你下载postgresql插件到你的应用程序上的heroku我做了,但是当我打开应用程序,它说不能得到/像预期的,但我去/books,它给了我heroku错误。当我这样做的时候:
heroku logs -t -a node-api-with-books
它给了我这个错误:
2021-03-03T03:25:31.515099+00:00 app[web.1]: code: 'ECONNREFUSED',
2021-03-03T03:25:31.515099+00:00 app[web.1]: syscall: 'connect',
2021-03-03T03:25:31.515099+00:00 app[web.1]: address: '127.0.0.1',
2021-03-03T03:25:31.515100+00:00 app[web.1]: port: 5432
2021-03-03T03:25:31.515100+00:00 app[web.1]: }
2021-03-03T03:25:31.542497+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/books" host=node-api-with-books.herokuapp.com request_id=83db8d38-c206-484a-8bca-a273ed8be8bd fwd="66.7.125.54" dyno=web.1 connect=5002ms service=95ms status=503 bytes=0 protocol=https
2021-03-03T03:25:31.578446+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-03-03T03:25:31.579040+00:00 app[web.1]: npm ERR! errno 1
2021-03-03T03:25:31.653173+00:00 app[web.1]: npm ERR! working-rest-api@1.0.0 start: `node index.js`
2021-03-03T03:25:31.653743+00:00 app[web.1]: npm ERR! Exit status 1
2021-03-03T03:25:31.656417+00:00 app[web.1]: npm ERR!
2021-03-03T03:25:31.656729+00:00 app[web.1]: npm ERR! Failed at the working-rest-api@1.0.0 start script.
2021-03-03T03:25:31.657018+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-03-03T03:25:31.693198+00:00 app[web.1]:
2021-03-03T03:25:31.700905+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-03-03T03:25:31.701084+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-03-03T03_25_31_668Z-debug.log
2021-03-03T03:25:31.868076+00:00 heroku[web.1]: Process exited with status 1
2021-03-03T03:25:32.005535+00:00 heroku[web.1]: State changed from up to crashed
2021-03-03T03:25:32.847159+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=node-api-with-books.herokuapp.com request_id=d669a8bb-5c76-4007-8e20-2323df702196 fwd="66.7.125.54" dyno=web.1 connect=1ms service= status=503 bytes= protocol=https
2021-03-03T03:57:13.968272+00:00 heroku[web.1]: State changed from crashed to starting
2021-03-03T03:57:19.191432+00:00 heroku[web.1]: Starting process with command `npm start`
2021-03-03T03:57:23.003539+00:00 app[web.1]:
2021-03-03T03:57:23.003564+00:00 app[web.1]: > working-rest-api@1.0.0 start /app
2021-03-03T03:57:23.003565+00:00 app[web.1]: > node index.js
2021-03-03T03:57:23.003565+00:00 app[web.1]:
2021-03-03T03:57:23.514091+00:00 app[web.1]: Server listening
2021-03-03T03:57:23.596725+00:00 heroku[web.1]: State changed from starting to up
2021-03-03T04:31:59.242314+00:00 heroku[web.1]: Idling
2021-03-03T04:31:59.270196+00:00 heroku[web.1]: State changed from up to down
2021-03-03T04:32:00.860211+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-03-03T04:32:01.033002+00:00 heroku[web.1]: Process exited with status 143
2021-03-04T23:41:06.257484+00:00 heroku[web.1]: Unidling
2021-03-04T23:41:06.279151+00:00 heroku[web.1]: State changed from down to starting
2021-03-04T23:41:09.533736+00:00 heroku[web.1]: Starting process with command `npm start`
2021-03-04T23:41:13.424801+00:00 app[web.1]:
2021-03-04T23:41:13.424844+00:00 app[web.1]: > working-rest-api@1.0.0 start /app
2021-03-04T23:41:13.424844+00:00 app[web.1]: > node index.js
2021-03-04T23:41:13.424844+00:00 app[web.1]:
2021-03-04T23:41:13.856750+00:00 app[web.1]: Server listening
2021-03-04T23:41:14.426074+00:00 heroku[web.1]: State changed from starting to up
2021-03-04T23:41:15.345417+00:00 heroku[router]: at=info method=GET path="/" host=node-api-with-books.herokuapp.com request_id=1fafdcec-9742-41d6-a530-a15755f7f0cc fwd="66.7.125.54" dyno=web.1 connect=1ms service=11ms status=404 bytes=415 protocol=https
2021-03-04T23:41:20.464200+00:00 app[web.1]: /app/index.js:12
2021-03-04T23:41:20.464217+00:00 app[web.1]: throw err;
2021-03-04T23:41:20.464218+00:00 app[web.1]: ^
2021-03-04T23:41:20.464218+00:00 app[web.1]:
2021-03-04T23:41:20.464219+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:5432
2021-03-04T23:41:20.464222+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
2021-03-04T23:41:20.464223+00:00 app[web.1]: errno: -111,
2021-03-04T23:41:20.464223+00:00 app[web.1]: code: 'ECONNREFUSED',
2021-03-04T23:41:20.464223+00:00 app[web.1]: syscall: 'connect',
2021-03-04T23:41:20.464224+00:00 app[web.1]: address: '127.0.0.1',
2021-03-04T23:41:20.464224+00:00 app[web.1]: port: 5432
2021-03-04T23:41:20.464225+00:00 app[web.1]: }
2021-03-04T23:41:20.477571+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/books" host=node-api-with-books.herokuapp.com request_id=24e2da67-be91-4e17-89b3-debef869bba4 fwd="66.7.125.54" dyno=web.1 connect=1ms service=49ms status=503 bytes=0 protocol=https
2021-03-04T23:41:20.484562+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-03-04T23:41:20.485036+00:00 app[web.1]: npm ERR! errno 1
2021-03-04T23:41:20.493801+00:00 app[web.1]: npm ERR! working-rest-api@1.0.0 start: `node index.js`
2021-03-04T23:41:20.494105+00:00 app[web.1]: npm ERR! Exit status 1
2021-03-04T23:41:20.494432+00:00 app[web.1]: npm ERR!
2021-03-04T23:41:20.494669+00:00 app[web.1]: npm ERR! Failed at the working-rest-api@1.0.0 start script.
2021-03-04T23:41:20.494947+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-03-04T23:41:20.511921+00:00 app[web.1]:
2021-03-04T23:41:20.512219+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-03-04T23:41:20.512381+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-03-04T23_41_20_495Z-debug.log
2021-03-04T23:41:20.920060+00:00 heroku[web.1]: Process exited with status 1
2021-03-04T23:41:20.981301+00:00 heroku[web.1]: State changed from up to crashed
2021-03-04T23:41:21.001047+00:00 heroku[web.1]: State changed from crashed to starting
2021-03-04T23:41:24.349422+00:00 heroku[web.1]: Starting process with command `npm start`
2021-03-04T23:41:28.760560+00:00 app[web.1]:
2021-03-04T23:41:28.760604+00:00 app[web.1]: > working-rest-api@1.0.0 start /app
2021-03-04T23:41:28.760605+00:00 app[web.1]: > node index.js
2021-03-04T23:41:28.760605+00:00 app[web.1]:
2021-03-04T23:41:29.460226+00:00 app[web.1]: Server listening
2021-03-04T23:41:29.767594+00:00 heroku[web.1]: State changed from starting to up
2021-03-04T23:41:30.782783+00:00 app[web.1]: /app/index.js:12
2021-03-04T23:41:30.782799+00:00 app[web.1]: throw err;
2021-03-04T23:41:30.782800+00:00 app[web.1]: ^
2021-03-04T23:41:30.782800+00:00 app[web.1]:
2021-03-04T23:41:30.782801+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:5432
2021-03-04T23:41:30.782802+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
2021-03-04T23:41:30.782802+00:00 app[web.1]: errno: -111,
2021-03-04T23:41:30.782803+00:00 app[web.1]: code: 'ECONNREFUSED',
2021-03-04T23:41:30.782803+00:00 app[web.1]: syscall: 'connect',
2021-03-04T23:41:30.782803+00:00 app[web.1]: address: '127.0.0.1',
2021-03-04T23:41:30.782804+00:00 app[web.1]: port: 5432
2021-03-04T23:41:30.782804+00:00 app[web.1]: }
2021-03-04T23:41:30.806119+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/books" host=node-api-with-books.herokuapp.com request_id=0476a454-a185-465c-9df3-f5e0adf6ec8f fwd="66.7.125.54" dyno=web.1 connect=1ms service=143ms status=503 bytes=0 protocol=https
2021-03-04T23:41:30.897859+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-03-04T23:41:30.901791+00:00 app[web.1]: npm ERR! errno 1
2021-03-04T23:41:30.940174+00:00 app[web.1]: npm ERR! working-rest-api@1.0.0 start: `node index.js`
2021-03-04T23:41:30.941393+00:00 app[web.1]: npm ERR! Exit status 1
2021-03-04T23:41:30.942380+00:00 app[web.1]: npm ERR!
2021-03-04T23:41:30.942813+00:00 app[web.1]: npm ERR! Failed at the working-rest-api@1.0.0 start script.
2021-03-04T23:41:30.943425+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-03-04T23:41:31.316808+00:00 app[web.1]:
2021-03-04T23:41:31.316994+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-03-04T23:41:31.317190+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-03-04T23_41_30_947Z-debug.log
2021-03-04T23:41:31.419624+00:00 heroku[web.1]: Process exited with status 1
2021-03-04T23:41:31.527952+00:00 heroku[web.1]: State changed from up to crashed
2021-03-04T23:41:32.128408+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=node-api-with-books.herokuapp.com request_id=7909f853-52aa-43dc-a228-3190e28b31b9 fwd="66.7.125.54" dyno=web.1 connect=0ms service= status=503 bytes= protocol=https
是否有我应该关注的部分,我如何使它工作?
你可能需要看看这个来更好地理解https://www.taniarascia.com/node-express-postgresql-heroku/
您正在尝试从heroku连接到本地postgreSQL数据库,请尝试在heroku仪表板中设置一个新的环境变量,如下所示:
NODE_ENV=production
或
你需要设置你所有的嫉妒。带有附加组件值的Var如下:
DB_USER=[your-add-on-user]
DB_PASSWORD=[your-add-on-pass]
DB_HOST=[your-add-on-host]
DB_PORT=5432
DB_DATABASE=[your-add-on-database]
来源:https://www.taniarascia.com/node-express-postgresql-heroku/#environment-variables