簡體   English   中英

節點 JS:部署到 heroku 后應用程序無法運行

[英]node JS: App is not working after deploying to heroku

這是我在節點 js 中的第一個項目,它在 localhost 上運行良好,但是當我在 heroku 上部署它時它不工作並顯示應用程序錯誤,我不知道是什么問題,下面是我的 heroku 日志和 server.js代碼。 有人可以幫我解決這個問題嗎?

提前致謝

 const express = require('express'); const morgan = require('morgan'); const mongoose = require('mongoose'); const dotenv = require('dotenv'); const jwt = require('jsonwebtoken'); const http = require('http'); const multer = require("multer"); const app = express(); const server = http.createServer(app); // corsfffffffff /************************************** Socket IO Related Start ************************************************/ // config dotenv dotenv.config(); const dbURI = process.env.MONGO_URL || "mongodb+srv://user:cvcvcv00S-@cluster0.jpij0.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"; mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true }).then(result => server.listen(process.env.PORT || 3000) ).catch(err => console.log(err)); app.set('view engine', 'ejs'); app.use(express.json); // app.use(express.urlencoded({ extended: true })); // app.use(morgan("dev")); app.use((req, res, next) => { res.locals.path = req.path; next(); }); const subscribersRouter = require('./routes/subscribers') app.use('/subscribers', subscribersRouter) app.get("/", function(req,res){ res.send("welcome to app"); })

heroku 日志:

 2021-12-09T19:45:22.688439+00:00 app[web.1]: - /app/app.js 2021-12-09T19:45:22.688440+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) 2021-12-09T19:45:22.688441+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:746:27) 2021-12-09T19:45:22.688442+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19) 2021-12-09T19:45:22.688442+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:93:18) 2021-12-09T19:45:22.688443+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:10:17) 2021-12-09T19:45:22.688443+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14) 2021-12-09T19:45:22.688443+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) 2021-12-09T19:45:22.688443+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32) 2021-12-09T19:45:22.688444+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12) 2021-12-09T19:45:22.688445+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) 2021-12-09T19:45:22.688446+00:00 app[web.1]: at internal/main/run_main_module.js:17:47 { 2021-12-09T19:45:22.688446+00:00 app[web.1]: code: 'MODULE_NOT_FOUND', 2021-12-09T19:45:22.688447+00:00 app[web.1]: requireStack: [ '/app/app.js' ] 2021-12-09T19:45:22.688447+00:00 app[web.1]: } 2021-12-09T19:45:22.697666+00:00 app[web.1]: npm ERR: code ELIFECYCLE 2021-12-09T19:45.22:697836+00.00 app[web:1]: npm ERR: errno 1 2021-12-09T19.45:22.701261+00:00 app[web.1]. npm ERR: api-master-nodejs@1.0:0 start: `node app.js` 2021-12-09T19:45.22:701307+00:00 app[web:1]. npm ERR: Exit status 1 2021-12-09T19.45:22:701436+00:00 app[web.1]: npm ERR. 2021-12-09T19:45.22.701475+00.00 app[web:1]: npm ERR. Failed at the api-master-nodejs@1:0.0 start script: 2021-12-09T19.45.22:701518+00:00 app[web.1]: npm ERR. This is probably not a problem with npm: There is likely additional logging output above: 2021-12-09T19:45.22:704190+00.00 app[web:1]: 2021-12-09T19:45:22.704261+00:00 app[web.1]: npm ERR. A complete log of this run can be found in. 2021-12-09T19:45:22.704300+00:00 app[web.1]: npm ERR: /app/:npm/_logs/2021-12-09T19_45_22_701Z-debug.log 2021-12-09T19:45.22:827246+00:00 heroku[web:1]. Process exited with status 1 2021-12-09T19:45:22.914958+00:00 heroku[web:1]. State changed from starting to crashed 2021-12-09T19:49:40.000000+00:00 app[api]: Build started by user sebaalchalabi@gmail.com 2021-12-09T19:49:56.223830+00:00 app[api]: Release v43 created by user sebaalchalabi@gmail.com 2021-12-09T19:49.56:223830+00:00 app[api]: Deploy 601b34e4 by user sebaalchalabi@gmail.com 2021-12-09T19:49:56:484890+00:00 heroku[web.1]: State changed from crashed to starting 2021-12-09T19.49:57:000000+00:00 app[api]. Build succeeded 2021-12-09T19:49.58:902781+00:00 heroku[web:1]. Starting process with command `npm start` 2021-12-09T19:50.00:133986+00.00 app[web.1]: 2021-12-09T19:50.00:134003+00.00 app[web:1]. > api-master-nodejs@1:0:0 start /app 2021-12-09T19.50:00.134003+00:00 app[web:1]: > node app.js 2021-12-09T19:50.00:134003+00:00 app[web:1]. 2021-12-09T19:50:01.187253+00.00 heroku[web.1]. State changed from starting to up 2021-12-09T19.50.32:260199+00:00 heroku[router]. at=error code=H12 desc="Request timeout" method=GET path="/" host=obscure-waters-05043:herokuapp.com request_id=cfbf2688-d4d4-4b7a-adf0-2663a1d7dace fwd="85:108:198:36" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https 2021-12-09T19:50.43:082048+00:00 heroku[web:1]. Restarting 2021-12-09T19:50.43:107251+00:00 heroku[web:1]. State changed from up to starting 2021-12-09T19:50:43.871385+00.00 heroku[web.1]. Stopping all processes with SIGTERM 2021-12-09T19.50.44.069113+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/favicon.ico" host=obscure-waters-05043:herokuapp.com request_id=49445fee-a0d0-4199-9adb-bf4314016e98 fwd="85:108:198:36" dyno=web.1 connect=0ms service=11418ms status=503 bytes=0 protocol=https 2021-12-09T19:50.44:193647+00:00 heroku[web:1]. Process exited with status 143 2021-12-09T19:50.45:155711+00:00 heroku[web:1]. Starting process with command `npm start` 2021-12-09T19:50.46:561346+00.00 app[web.1]: 2021-12-09T19:50.46:561360+00.00 app[web:1]. > api-master-nodejs@1:0:0 start /app 2021-12-09T19.50:46.561361+00:00 app[web:1]: > node app.js 2021-12-09T19:50.46:561361+00:00 app[web:1]. 2021-12-09T19:50:47.295414+00:00 heroku[web:1]. State changed from starting to up 2021-12-09T19:51:51.000000+00:00 app[api]: Build started by user sebaalchalabi@gmail.com 2021-12-09T19:52:08.296910+00:00 app[api]: Deploy 202801b6 by user sebaalchalabi@gmail.com 2021-12-09T19:52.08:296910+00:00 app[api]: Release v44 created by user sebaalchalabi@gmail.com 2021-12-09T19:52.08:590301+00:00 heroku[web:1]. Restarting 2021-12-09T19:52:08:615504+00:00 heroku[web.1]: State changed from up to starting 2021-12-09T19.52:09:000000+00:00 app[api]. Build succeeded 2021-12-09T19:52.09:331866+00:00 heroku[web:1]. Stopping all processes with SIGTERM 2021-12-09T19:52.09:574745+00:00 heroku[web:1]. Process exited with status 143 2021-12-09T19:52.10:680588+00:00 heroku[web:1]. Starting process with command `npm start` 2021-12-09T19:52.11:875404+00.00 app[web.1]: 2021-12-09T19:52.11:875420+00.00 app[web:1]. > api-master-nodejs@1:0:0 start /app 2021-12-09T19.52:11.875420+00:00 app[web:1]: > node app.js 2021-12-09T19:52.11:875420+00:00 app[web:1]. 2021-12-09T19:52:12.491955+00.00 heroku[web.1]. State changed from starting to up 2021-12-09T19.53.21:013488+00:00 heroku[router]. at=error code=H12 desc="Request timeout" method=GET path="/" host=obscure-waters-05043:herokuapp.com request_id=3d66d37c-eec6-44d2-8792-a7ddff579766 fwd="85:108:198:36" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https 2021-12-09T19:53.41:188552+00:00 heroku[web:1]. Restarting 2021-12-09T19:53.41:191420+00:00 heroku[web:1]. State changed from up to starting 2021-12-09T19:53:41.978236+00.00 heroku[web.1]. Stopping all processes with SIGTERM 2021-12-09T19.53.42.180105+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/favicon.ico" host=obscure-waters-05043:herokuapp.com request_id=98bb6ae6-b3ec-4206-95a4-6279e7aff78b fwd="85:108:198:36" dyno=web.1 connect=0ms service=20953ms status=503 bytes=0 protocol=https 2021-12-09T19:53.42:314257+00:00 heroku[web:1]. Process exited with status 143 2021-12-09T19:53.43:672529+00:00 heroku[web:1]. Starting process with command `npm start` 2021-12-09T19:53.45:699311+00.00 app[web.1]: 2021-12-09T19:53.45:699323+00.00 app[web:1]. > api-master-nodejs@1:0:0 start /app 2021-12-09T19.53:45.699324+00:00 app[web:1]: > node app.js 2021-12-09T19:53.45:699324+00:00 app[web:1]. 2021-12-09T19:53.47:034852+00:00 heroku[web:1]. State changed from starting to up 2021-12-09T19:57.01:713660+00:00 heroku[web:1]. Restarting 2021-12-09T19:57.01:847677+00:00 heroku[web:1]. State changed from up to starting 2021-12-09T19:57.02:852486+00:00 heroku[web:1]. Stopping all processes with SIGTERM 2021-12-09T19:57.03:172988+00:00 heroku[web:1]. Process exited with status 143 2021-12-09T19:57.04:132727+00:00 heroku[web:1]. Starting process with command `npm start` 2021-12-09T19:57.05:215604+00.00 app[web.1]: 2021-12-09T19:57.05:215618+00.00 app[web:1]. > api-master-nodejs@1:0:0 start /app 2021-12-09T19.57:05.215618+00:00 app[web:1]: > node app.js 2021-12-09T19:57.05:215618+00:00 app[web:1]. 2021-12-09T19:57:05.821299+00:00 heroku[web:1]. State changed from starting to up 2021-12-09T19:57:15.000000+00:00 app[api]: Build started by user sebaalchalabi@gmail.com 2021-12-09T19:57:30.843649+00:00 app[api]: Release v45 created by user sebaalchalabi@gmail.com 2021-12-09T19:57:30:843649+00:00 app[api]. Deploy 338ae6f5 by user sebaalchalabi@gmail:com 2021-12-09T19.57:31:000000+00:00 app[api]. Build succeeded 2021-12-09T19:57.31:085978+00:00 heroku[web:1]. Restarting 2021-12-09T19:57.31:201283+00:00 heroku[web:1]. State changed from up to starting 2021-12-09T19:57.31:880715+00:00 heroku[web:1]. Stopping all processes with SIGTERM 2021-12-09T19:57.32:065101+00:00 heroku[web:1]. Process exited with status 143 2021-12-09T19:57.33:428958+00:00 heroku[web:1]. Starting process with command `npm start` 2021-12-09T19:57.34:677151+00.00 app[web.1]: 2021-12-09T19:57.34:677180+00.00 app[web:1]. > api-master-nodejs@1:0:0 start /app 2021-12-09T19.57:34.677181+00:00 app[web:1]: > node app.js 2021-12-09T19:57.34:677181+00:00 app[web.1]: 2021-12-09T19:57:35.761777+00:00 heroku[web.1]: State changed from starting to up

您是否使用npm install --save <module>安裝了所有模塊? 如果不包含--save選項,則模塊不會寫入package.json文件,Heroku 使用該文件自動下載依賴項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM