gpt4 book ai didi

javascript - heroku Node js redis出错

转载 作者:可可西里 更新时间:2023-11-01 11:25:00 25 4
gpt4 key购买 nike

我正在尝试在 heroku 上部署应用程序,但遇到了一些错误。这是我的应用程序日志。我该如何解决这个问题??

2017-11-30T21:25:51.461297+00:00 app[web.1]: 
2017-11-30T21:25:51.453647+00:00 app[web.1]: npm ERR! Failed at the redisExample@1.0.0 start script.
2017-11-30T21:25:51.453488+00:00 app[web.1]: npm ERR!
2017-11-30T21:25:51.453823+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-11-30T21:25:51.453192+00:00 app[web.1]: npm ERR! Exit status 1
2017-11-30T21:25:51.461495+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-11-30T21:25:51.461625+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2017-11-30T21_25_51_455Z-debug.log
2017-11-30T21:25:51.575216+00:00 heroku[web.1]: Process exited with status 1
2017-11-30T21:25:51.589604+00:00 heroku[web.1]: State changed from starting to crashed
2017-11-30T21:25:52.424042+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calm-bastion-97639.herokuapp.com request_id=e2e56b20-6479-4e14-8199-f2aba1a72ab5 fwd="74.214.48.190" dyno= connect= service= status=503 bytes= protocol=https
2017-11-30T21:25:52.503819+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calm-bastion-97639.herokuapp.com request_id=4adab6fa-0e19-446b-bc0d-7a7bc0f4e5c5 fwd="74.214.48.190" dyno= connect= service= status=503 bytes= protocol=https

我的package.json文件的内容是

{
"name": "redisExample",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "*",
"ejs": "^2.4.2",
"express": "^4.16.2",
"morgan": "*",
"redis": "^2.8.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ashpixar/redisExample.git"
},
"keywords": [],
"bugs": {
"url": "https://github.com/ashpixar/redisExample/issues"
},
"homepage": "https://github.com/ashpixar/redisExample#readme"
}

我的js文件是 const express = require(' express ') const app = express()

app.use(express.static('public'))

app.listen(process.env.PORT || 8080, () => console.log('all is ok'));

const redis = require('redis')
var client = redis.createClient(process.env.REDIS_URL);

最佳答案

当未指定 procfile 时,heroku 通过执行 npm start 加载 nodejs 应用。

您的 package.json 没有“启动”脚本。

尝试在您的 package.json 中添加启动脚本

 "scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
}

Heroku Procfile documentation

我在我的环境中测试了该项目并将其部署在 heroku 上,启动脚本运行良好。在部署过程中你一定错过了一些步骤,没有日志很难说。

无论如何,按照这些步骤,您应该能够部署该应用。

  1. 如果你还没有这样做,你必须安装redis插件你的 heroku 实例。

    下载并安装 heroku CLI here ,从命令行运行heroku addons:create heroku-redis:hobby-dev -a

    这将创建带有 hobby-dev 计划的 REDIS 插件(它是免费的)。只要你运行这个命令,它就会在控制台查看redis插件创建进度。

    它类似于使用 heroku addons:info redis-curly-19008 检查创作进度'

    一旦创建了插件,您应该会在您的应用中看到Heroku 上的设置,它还添加了一个新的环境变量REDIS_URL。

  2. node_modules 文件夹不应该在你的 repo 中,npm模块在安装时由 heroku 自动安装应用程序,要在本地安装它只需运行命令npm install 从您的根项目。

    为了避免提交你不想提交的东西,创建一个文件在项目根目录中调用 .gitignore 并添加以下内容内容:

    /node_modulesnpm-debug.log.DS_Store/*.env/*.env.*/.project/.settings
  3. 由于您使用 github 作为存储库,因此提交项目更改并部署

  4. 查看日志,部署完成后,访问你的应用程序。它应该是这样的:<强> https://yourappname.herokuapp.com/

我建议关注 this guide 了解更多详情

关于javascript - heroku Node js redis出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47583417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com