繁体   English   中英

使用 Heroku 和 GitHub 部署 Node.js 应用程序

[英]Deploying Node.js App Using Heroku & GitHub

我目前一直在花费数小时尝试解决我在尝试启动我的 heroku 应用程序时遇到的一些运行时错误。 我附上了我的日志、文件结构、package.json 文件和 Procfile 作为参考。 我知道我遗漏了一些东西,但我可以确定它是什么。 在此问题上的任何帮助将不胜感激,我认为使用 Heroku 不会遇到这么多问题。

在此处输入图像描述 这是我的文件结构->

{
  "name": "pokedex-app",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon server.js",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^5.0.1",
    "cjs-loader": "^0.1.0",
    "cookie-parser": "^1.4.5",
    "ejs": "^3.1.6",
    "express": "^4.17.1",
    "express-flash": "0.0.2",
    "express-session": "^1.17.2",
    "google-auth-library": "^7.6.1",
    "method-override": "^3.0.0",
    "morgan": "^1.10.0"
  },
  "devDependencies": {
    "dotenv": "^10.0.0",
    "nodemon": "^2.0.12"
  },
  "engines": {
    "node": "14.x",
    "npm": "7.x"
  }
}

2021-08-14T15:06:07.769961+00:00 app[api]: Release v15 created by user berriosa13@gmail.com
2021-08-14T15:06:08.010780+00:00 heroku[web.1]: State changed from crashed to starting
2021-08-14T15:06:11.223810+00:00 heroku[web.1]: Starting process with command `node server.js`
2021-08-14T15:06:12.903922+00:00 app[web.1]: internal/modules/cjs/loader.js:905
2021-08-14T15:06:12.903938+00:00 app[web.1]: throw err;
2021-08-14T15:06:12.903939+00:00 app[web.1]: ^
2021-08-14T15:06:12.903939+00:00 app[web.1]:
2021-08-14T15:06:12.903939+00:00 app[web.1]: Error: Cannot find module 'dotenv'
2021-08-14T15:06:12.903939+00:00 app[web.1]: Require stack:
2021-08-14T15:06:12.903939+00:00 app[web.1]: - /app/server.js
2021-08-14T15:06:12.903940+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
2021-08-14T15:06:12.903940+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:746:27)
2021-08-14T15:06:12.903940+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)    
2021-08-14T15:06:12.903941+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:92:18)
2021-08-14T15:06:12.903941+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:1:1)
2021-08-14T15:06:12.903941+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)  
2021-08-14T15:06:12.903941+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-08-14T15:06:12.903942+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)       
2021-08-14T15:06:12.903942+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:14)
2021-08-14T15:06:12.903943+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
2021-08-14T15:06:12.903943+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-08-14T15:06:12.903943+00:00 app[web.1]: requireStack: [ '/app/server.js' ]
2021-08-14T15:06:12.903944+00:00 app[web.1]: }
2021-08-14T15:06:12.960936+00:00 heroku[web.1]: Process exited with status 1
2021-08-14T15:06:13.073784+00:00 heroku[web.1]: State changed from starting to crashed
2021-08-14T15:06:54.527085+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" 
host=anthonys-pokedex.herokuapp.com request_id=8bae5904-9302-4244-9b58-ab87ddb462b8 fwd="73.165.31.162" dyno= connect= service= status=503 bytes= protocol=https
2021-08-14T15:06:54.895843+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=anthonys-pokedex.herokuapp.com request_id=f3fad693-09d3-441d-8ef6-4af197454c4a fwd="73.165.31.162" dyno= connect= service= status=503 bytes= protocol=https

按照本教程进行操作:这对我有用。

https://www.freecodecamp.org/news/how-to-deploy-a-nodejs-app-to-heroku-from-github-without-installing-heroku-on-your-machine-433bec770efe/

如何将 NodeJS 应用程序从 Github 部署到 Heroku(无需在您的机器上安装 Heroku):

在这个演示中,我们将研究如何将你的酷 NodeJS 应用程序部署到 Heroku。在这个演示结束时,我们将有一个基本的 Hello World 应用程序在公共域上运行,任何人都可以访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM