I have looked through a lot of similar topics and have so far been unable to resolve my problem.
I created a MERN app, used Amazon for my assets and tried to deploy it on Heroku.
My app works locally but when I deployed it on Heroku, I got a 'Application Error'.
When I take a look at the heroku logs --tail, this is the final errors I got :
2019-04-27T12:49:01.084214+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calm-earth-15269.herokuapp.com request_id=b2953cc1-6894-4697-8fc4-17d5012c536e fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https
2019-04-27T12:49:01.622395+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calm-earth-15269.herokuapp.com request_id=2a9fbdbb-a35d-4ba1-a032-b263110e10db fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https
And this is the complete log :
2019-04-27T12:48:09.000000+00:00 app[api]: Build succeeded
2019-04-27T12:48:24.009559+00:00 heroku[web.1]: Starting process with command `npm start`
2019-04-27T12:48:27.790744+00:00 app[web.1]:
2019-04-27T12:48:27.790767+00:00 app[web.1]: > joystock#1.0.0 start /app
2019-04-27T12:48:27.790768+00:00 app[web.1]: > node server.js
2019-04-27T12:48:27.790770+00:00 app[web.1]:
2019-04-27T12:48:29.369354+00:00 app[web.1]:
2019-04-27T12:48:29.369392+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:465
2019-04-27T12:48:29.369396+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2019-04-27T12:48:29.369397+00:00 app[web.1]: ^
2019-04-27T12:48:29.369917+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2019-04-27T12:48:29.369920+00:00 app[web.1]: at new MongooseError (/app/node_modules/mongoose/lib/error/mongooseError.js:14:11)
2019-04-27T12:48:29.369923+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:465:11)
2019-04-27T12:48:29.369925+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:289:15)
2019-04-27T12:48:29.369928+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:25:4)
2019-04-27T12:48:29.369930+00:00 app[web.1]: at Module._compile (module.js:653:30)
2019-04-27T12:48:29.369932+00:00 app[web.1]: at Object.Module._extensions..js (module.js:664:10)
2019-04-27T12:48:29.369933+00:00 app[web.1]: at Module.load (module.js:566:32)
2019-04-27T12:48:29.369935+00:00 app[web.1]: at tryModuleLoad (module.js:506:12)
2019-04-27T12:48:29.369936+00:00 app[web.1]: at Function.Module._load (module.js:498:3)
2019-04-27T12:48:29.369938+00:00 app[web.1]: at Function.Module.runMain (module.js:694:10)
2019-04-27T12:48:29.369939+00:00 app[web.1]: at startup (bootstrap_node.js:204:16)
2019-04-27T12:48:29.369942+00:00 app[web.1]: at bootstrap_node.js:625:3
2019-04-27T12:48:29.430850+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-04-27T12:48:29.434765+00:00 app[web.1]: npm ERR! errno 1
2019-04-27T12:48:29.436805+00:00 app[web.1]: npm ERR! joystock#1.0.0 start: `node server.js`
2019-04-27T12:48:29.437062+00:00 app[web.1]: npm ERR! Exit status 1
2019-04-27T12:48:29.437419+00:00 app[web.1]: npm ERR!
2019-04-27T12:48:29.437721+00:00 app[web.1]: npm ERR! Failed at the joystock#1.0.0 start script.
2019-04-27T12:48:29.438013+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-04-27T12:48:29.457869+00:00 app[web.1]:
2019-04-27T12:48:29.458356+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-04-27T12:48:29.458709+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-04-27T12_48_29_440Z-debug.log
2019-04-27T12:48:29.555420+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-27T12:48:29.559599+00:00 heroku[web.1]: State changed from crashed to starting
2019-04-27T12:48:29.536335+00:00 heroku[web.1]: Process exited with status 1
2019-04-27T12:48:38.161883+00:00 heroku[web.1]: Starting process with command `npm start`
2019-04-27T12:48:40.468366+00:00 app[web.1]:
2019-04-27T12:48:40.468385+00:00 app[web.1]: > joystock#1.0.0 start /app
2019-04-27T12:48:40.468387+00:00 app[web.1]: > node server.js
2019-04-27T12:48:40.468388+00:00 app[web.1]:
2019-04-27T12:48:41.210741+00:00 app[web.1]:
2019-04-27T12:48:41.210778+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:465
2019-04-27T12:48:41.210781+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2019-04-27T12:48:41.210783+00:00 app[web.1]: ^
2019-04-27T12:48:41.211208+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2019-04-27T12:48:41.211212+00:00 app[web.1]: at new MongooseError (/app/node_modules/mongoose/lib/error/mongooseError.js:14:11)
2019-04-27T12:48:41.211214+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:465:11)
2019-04-27T12:48:41.211216+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:289:15)
2019-04-27T12:48:41.211218+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:25:4)
2019-04-27T12:48:41.211219+00:00 app[web.1]: at Module._compile (module.js:653:30)
2019-04-27T12:48:41.211221+00:00 app[web.1]: at Object.Module._extensions..js (module.js:664:10)
2019-04-27T12:48:41.211222+00:00 app[web.1]: at Module.load (module.js:566:32)
2019-04-27T12:48:41.211224+00:00 app[web.1]: at tryModuleLoad (module.js:506:12)
2019-04-27T12:48:41.211225+00:00 app[web.1]: at Function.Module._load (module.js:498:3)
2019-04-27T12:48:41.211227+00:00 app[web.1]: at Function.Module.runMain (module.js:694:10)
2019-04-27T12:48:41.211228+00:00 app[web.1]: at startup (bootstrap_node.js:204:16)
2019-04-27T12:48:41.211231+00:00 app[web.1]: at bootstrap_node.js:625:3
2019-04-27T12:48:41.220629+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-04-27T12:48:41.221020+00:00 app[web.1]: npm ERR! errno 1
2019-04-27T12:48:41.222262+00:00 app[web.1]: npm ERR! joystock#1.0.0 start: `node server.js`
2019-04-27T12:48:41.222424+00:00 app[web.1]: npm ERR! Exit status 1
2019-04-27T12:48:41.222687+00:00 app[web.1]: npm ERR!
2019-04-27T12:48:41.222855+00:00 app[web.1]: npm ERR! Failed at the joystock#1.0.0 start script.
2019-04-27T12:48:41.223019+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-04-27T12:48:41.228089+00:00 app[web.1]:
2019-04-27T12:48:41.228288+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-04-27T12:48:41.228431+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-04-27T12_48_41_224Z-debug.log
2019-04-27T12:48:41.314693+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-27T12:48:41.291941+00:00 heroku[web.1]: Process exited with status 1
2019-04-27T12:49:01.084214+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calm-earth-15269.herokuapp.com request_id=b2953cc1-6894-4697-8fc4-17d5012c536e fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https
2019-04-27T12:49:01.622395+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calm-earth-15269.herokuapp.com request_id=2a9fbdbb-a35d-4ba1-a032-b263110e10db fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https
I've already tried/checked :
The port
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Joystock Server running on port ${port}`));
Tried :
heroku restart
Add the engines version in my package.json file
"engines": {
"node": "8.12.0",
"npm": "6.4.1"
},
My config vars (mongoURI) are correctly defined in my heroku settings for this app.
I also tried to recreate the app completely, from scratch, and everything is up to date.
At first, I add no route defined for '/', so I tried to add one in routes/tracks.js
router.get('/', (req, res) => {
res.redirect('/all/page-1');
});
With or without this route, I got the same result.
...and I always end up with the same errors.
This is my current git repos for this app :
https://github.com/Karaza/joystock
I am out of ideas for what to try to do next for fixing my app.
Thank you in advance for you help (:
in file: joystock/config/keys.js... ensure that NODE_ENV is production? there no keys_dev file.
if (process.env.NODE_ENV === 'production') {
module.exports = require('./keys_prod');
} else {
module.exports = require('./keys_dev');
}
i'm not familiar with heroku, but looks like you disable production mode.
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
So i think need check:
process.env.MONGO_URI
process.env.NODE_ENV
In my config vars, I tried to define mongoURI instead of MONGO_URI
It's working now :)
Related
My app works locally, but when trying to deploy I get code=H10. I have tried looking up code=H10 failures, but they all see to lead to changes with process.env.PORT changes, which I have already done in various ways.
This is my first time deploying to heroku, so sorry if I am missing some important information.
Any advice will be much appreciated.
My logs:
2021-05-16T23:27:11.291289+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
2021-05-16T23:27:11.291289+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 {
2021-05-16T23:27:11.291289+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-05-16T23:27:11.291290+00:00 app[web.1]: requireStack: []
2021-05-16T23:27:11.291290+00:00 app[web.1]: }
2021-05-16T23:27:11.341722+00:00 heroku[web.1]: Process exited with status 1
2021-05-16T23:27:11.432934+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-16T23:27:55.798013+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thenewslab.herokuapp.com request_id=3428bce1-739d-47ed-9205-9859475e0e22 fwd="46.69.82.216" dyno= connect= service= status=503 bytes= protocol=https
2021-05-16T23:33:49.000000+00:00 app[api]: Build started by user joshuamacleod#live.com
2021-05-16T23:36:06.038437+00:00 app[api]: Release v17 created by user joshuamacleod#live.com
2021-05-16T23:36:06.038437+00:00 app[api]: Deploy 31855de1 by user joshuamacleod#live.com
2021-05-16T23:36:06.264449+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-16T23:36:07.000000+00:00 app[api]: Build succeeded
2021-05-16T23:36:19.886178+00:00 heroku[web.1]: Starting process with command `node build/server.js`
2021-05-16T23:36:22.175404+00:00 app[web.1]: node:internal/modules/cjs/loader:944
2021-05-16T23:36:22.175424+00:00 app[web.1]: throw err;
2021-05-16T23:36:22.175425+00:00 app[web.1]: ^
2021-05-16T23:36:22.175425+00:00 app[web.1]:
2021-05-16T23:36:22.175426+00:00 app[web.1]: Error: Cannot find module '/app/build/server.js'
2021-05-16T23:36:22.175426+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
2021-05-16T23:36:22.175427+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:774:27)
2021-05-16T23:36:22.175427+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
2021-05-16T23:36:22.175428+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 {
2021-05-16T23:36:22.175428+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-05-16T23:36:22.175429+00:00 app[web.1]: requireStack: []
2021-05-16T23:36:22.175429+00:00 app[web.1]: }
2021-05-16T23:36:22.240102+00:00 heroku[web.1]: Process exited with status 1
2021-05-16T23:36:22.322859+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-16T23:36:50.313742+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thenewslab.herokuapp.com request_id=0e8e0047-c98d-4126-9008-c50c7d927320 fwd="46.69.82.216" dyno= connect= service= status=503 bytes= protocol=https
2021-05-16T23:43:04.802415+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-16T23:43:19.981689+00:00 heroku[web.1]: Starting process with command `node build/server.js`
2021-05-16T23:43:22.004092+00:00 app[web.1]: node:internal/modules/cjs/loader:944
2021-05-16T23:43:22.004127+00:00 app[web.1]: throw err;
2021-05-16T23:43:22.004127+00:00 app[web.1]: ^
2021-05-16T23:43:22.004128+00:00 app[web.1]:
2021-05-16T23:43:22.004128+00:00 app[web.1]: Error: Cannot find module '/app/build/server.js'
2021-05-16T23:43:22.004129+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
2021-05-16T23:43:22.004129+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:774:27)
2021-05-16T23:43:22.004130+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
2021-05-16T23:43:22.004130+00:00 app[web.1]: at node:internal/main/run_main_module:17:47 {
2021-05-16T23:43:22.004130+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-05-16T23:43:22.004131+00:00 app[web.1]: requireStack: []
2021-05-16T23:43:22.004131+00:00 app[web.1]: }
2021-05-16T23:43:22.064674+00:00 heroku[web.1]: Process exited with status 1
2021-05-16T23:43:22.121461+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-16T23:56:01.000000+00:00 app[api]: Build started by user joshuamacleod#live.com
2021-05-16T23:58:17.578622+00:00 app[api]: Release v18 created by user joshuamacleod#live.com
2021-05-16T23:58:17.578622+00:00 app[api]: Deploy 09023d82 by user joshuamacleod#live.com
2021-05-16T23:58:17.959761+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-16T23:58:19.000000+00:00 app[api]: Build succeeded
2021-05-16T23:58:35.537730+00:00 heroku[web.1]: Starting process with command `node server.js`
2021-05-16T23:58:38.809616+00:00 app[web.1]: node:internal/modules/cjs/loader:944
2021-05-16T23:58:38.809639+00:00 app[web.1]: throw err;
2021-05-16T23:58:38.809640+00:00 app[web.1]: ^
2021-05-16T23:58:38.809640+00:00 app[web.1]:
2021-05-16T23:58:38.809640+00:00 app[web.1]: Error: Cannot find module '/Users/joshua/makers/thenewslab/news-server/db'
2021-05-16T23:58:38.809641+00:00 app[web.1]: Require stack:
2021-05-16T23:58:38.809641+00:00 app[web.1]: - /app/routes/api/users.js
2021-05-16T23:58:38.809641+00:00 app[web.1]: - /app/server.js
2021-05-16T23:58:38.809642+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
2021-05-16T23:58:38.809643+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:774:27)
2021-05-16T23:58:38.809643+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1013:19)
2021-05-16T23:58:38.809643+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:93:18)
2021-05-16T23:58:38.809644+00:00 app[web.1]: at Object.<anonymous> (/app/routes/api/users.js:5:12)
2021-05-16T23:58:38.809644+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1109:14)
2021-05-16T23:58:38.809644+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
2021-05-16T23:58:38.809645+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:989:32)
2021-05-16T23:58:38.809645+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:829:14)
2021-05-16T23:58:38.809645+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1013:19) {
2021-05-16T23:58:38.809646+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-05-16T23:58:38.809646+00:00 app[web.1]: requireStack: [ '/app/routes/api/users.js', '/app/server.js' ]
2021-05-16T23:58:38.809648+00:00 app[web.1]: }
2021-05-16T23:58:38.902832+00:00 heroku[web.1]: Process exited with status 1
2021-05-16T23:58:38.974809+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-16T23:58:38.986788+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-16T23:58:50.650040+00:00 heroku[web.1]: Starting process with command `node server.js`
2021-05-16T23:58:52.992272+00:00 app[web.1]: node:internal/modules/cjs/loader:944
2021-05-16T23:58:52.992286+00:00 app[web.1]: throw err;
2021-05-16T23:58:52.992286+00:00 app[web.1]: ^
2021-05-16T23:58:52.992286+00:00 app[web.1]:
2021-05-16T23:58:52.992287+00:00 app[web.1]: Error: Cannot find module '/Users/joshua/makers/thenewslab/news-server/db'
2021-05-16T23:58:52.992287+00:00 app[web.1]: Require stack:
2021-05-16T23:58:52.992287+00:00 app[web.1]: - /app/routes/api/users.js
2021-05-16T23:58:52.992288+00:00 app[web.1]: - /app/server.js
2021-05-16T23:58:52.992288+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
2021-05-16T23:58:52.992288+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:774:27)
2021-05-16T23:58:52.992289+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1013:19)
2021-05-16T23:58:52.992289+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:93:18)
2021-05-16T23:58:52.992289+00:00 app[web.1]: at Object.<anonymous> (/app/routes/api/users.js:5:12)
2021-05-16T23:58:52.992290+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1109:14)
2021-05-16T23:58:52.992290+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
2021-05-16T23:58:52.992290+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:989:32)
2021-05-16T23:58:52.992290+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:829:14)
2021-05-16T23:58:52.992290+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1013:19) {
2021-05-16T23:58:52.992294+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-05-16T23:58:52.992294+00:00 app[web.1]: requireStack: [ '/app/routes/api/users.js', '/app/server.js' ]
2021-05-16T23:58:52.992294+00:00 app[web.1]: }
2021-05-16T23:58:53.061937+00:00 heroku[web.1]: Process exited with status 1
2021-05-16T23:58:53.120732+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-16T23:59:37.345240+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thenewslab.herokuapp.com request_id=76cb051f-7ecc-451e-93cc-50f56beac59a fwd="46.69.82.216" dyno= connect= service= status=503 bytes= protocol=https
My server:
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const passport = require("passport");
const users = require("./routes/api/users");
const path = require("path");
const db = require('./db')
const articleRouter = require('./routes/article-router')
const app = express()
const server = process.env.PORT || 5000
app.use(bodyParser.urlencoded({
extended: true
}))
app.use(cors())
app.use(bodyParser.json())
app.use(passport.initialize());
app.use(express.static(path.join(__dirname, "client", "build")))
require("./config/passport")(passport);
db.on('error', console.error.bind(console, 'MongoDB connection error:'))
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
app.use('/api', articleRouter)
app.use("/api/users", users);
app.listen(server, () => console.log(`Server running on port ${server}`))
My package.json:
{
"name": "news-server",
"version": "1.0.0",
"engines": {
"node": ">= 14.15.5",
"npm": "6.14.11"
},
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js",
"heroku-postbuild": "cd news-front && npm install --only=dev && npm install && npm run build"
}
My Procfile:
web: node server.js
A Procfile is not always necessary to deploy Node.js apps to Heroku, however, your package.json is very very important. The package.json file should include the modules to be installed. Which is missing.
The logs clearly say code: 'MODULE_NOT_FOUND', which means node_modules/ are missing.
You might have node_modules/ in your local system, but Heroku ignores it. It takes package.json and freshly starts to download it.
Heroku runs something like this. It Deletes node_modules/ then runs "npm install" then "node server.js"
For you, I would advice to always save your node_modules/ to package.json. This can be done while installing modules easily by adding --save
To debug this, do
"npm install --save express cors passport"
You can do this or do
"npm i --save express"
"npm i --save cors"
"npm i --save passport"
It is then showing me ./routes/api/users - I hope you have it.
i'm deploying my first app on heroku, i pushed the code on GitHub, add Heroku keys(because ), created the heroku app on terminal and finally git push heroku master.
The app is very basic, but it doesn't work, and i can't even find a decent log information to work with!
This is the long log that i found.
Hope someone could help me!
2019-12-06T00:11:00.862870+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) {
2019-12-06T00:11:00.862872+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2019-12-06T00:11:00.862874+00:00 app[web.1]: requireStack: [ '/app/src/app.js' ]
2019-12-06T00:11:00.862876+00:00 app[web.1]: }
2019-12-06T00:11:00.870032+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-12-06T00:11:00.871330+00:00 app[web.1]: npm ERR! errno 1
2019-12-06T00:11:00.871733+00:00 app[web.1]: npm ERR! 1-Heroku#1.0.0 start: `node src/app.js`
2019-12-06T00:11:00.872684+00:00 app[web.1]: npm ERR! Exit status 1
2019-12-06T00:11:00.872690+00:00 app[web.1]: npm ERR!
2019-12-06T00:11:00.872695+00:00 app[web.1]: npm ERR! Failed at the 1-Heroku#1.0.0 start script.
2019-12-06T00:11:00.872698+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-12-06T00:11:02.538864+00:00 app[web.1]:
2019-12-06T00:11:02.542433+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-12-06T00:11:02.542703+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-12-06T00_11_00_875Z-debug.log
2019-12-06T00:11:02.625046+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-06T00:11:02.614891+00:00 heroku[web.1]: Process exited with status 1
2019-12-06T00:18:05.000000+00:00 app[api]: Build started by user cristiano.piscioneri.dev#gmail.com
2019-12-06T00:18:24.105108+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=c-neri-heroku.herokuapp.com request_id=b779201e-bb33-420a-9aea-cd67d026040e fwd="151.32.4.219" dyno= connect= service= status=503 bytes= protocol=https
2019-12-06T00:18:48.614900+00:00 app[api]: Deploy c57e0dc3 by user cristiano.piscioneri.dev#gmail.com
2019-12-06T00:18:48.614900+00:00 app[api]: Release v4 created by user cristiano.piscioneri.dev#gmail.com
2019-12-06T00:18:48.892841+00:00 heroku[web.1]: State changed from crashed to starting
2019-12-06T00:18:49.000000+00:00 app[api]: Build succeeded
2019-12-06T00:18:52.277413+00:00 heroku[web.1]: Starting process with command `npm start`
2019-12-06T00:18:55.506035+00:00 app[web.1]:
2019-12-06T00:18:55.506063+00:00 app[web.1]: > 1-Heroku#1.0.0 start /app
2019-12-06T00:18:55.506065+00:00 app[web.1]: > node src/app.js
2019-12-06T00:18:55.506067+00:00 app[web.1]:
2019-12-06T00:18:55.809888+00:00 app[web.1]: internal/modules/cjs/loader.js:800
2019-12-06T00:18:55.809932+00:00 app[web.1]: throw err;
2019-12-06T00:18:55.809934+00:00 app[web.1]: ^
2019-12-06T00:18:55.809936+00:00 app[web.1]:
2019-12-06T00:18:55.809939+00:00 app[web.1]: Error: Cannot find module 'hbs'
2019-12-06T00:18:55.809941+00:00 app[web.1]: Require stack:
2019-12-06T00:18:55.809943+00:00 app[web.1]: - /app/src/app.js
2019-12-06T00:18:55.809945+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
2019-12-06T00:18:55.809947+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:690:27)
2019-12-06T00:18:55.809950+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:852:19)
2019-12-06T00:18:55.809952+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-12-06T00:18:55.809954+00:00 app[web.1]: at Object.<anonymous> (/app/src/app.js:5:13)
2019-12-06T00:18:55.809956+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:959:30)
2019-12-06T00:18:55.809958+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
2019-12-06T00:18:55.809960+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:815:32)
2019-12-06T00:18:55.809962+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:727:14)
2019-12-06T00:18:55.809964+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) {
2019-12-06T00:18:55.809966+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2019-12-06T00:18:55.809968+00:00 app[web.1]: requireStack: [ '/app/src/app.js' ]
2019-12-06T00:18:55.809970+00:00 app[web.1]: }
2019-12-06T00:18:55.853916+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-12-06T00:18:55.854597+00:00 app[web.1]: npm ERR! errno 1
2019-12-06T00:18:55.858952+00:00 app[web.1]: npm ERR! 1-Heroku#1.0.0 start: `node src/app.js`
2019-12-06T00:18:55.859163+00:00 app[web.1]: npm ERR! Exit status 1
2019-12-06T00:18:55.859694+00:00 app[web.1]: npm ERR!
2019-12-06T00:18:55.859697+00:00 app[web.1]: npm ERR! Failed at the 1-Heroku#1.0.0 start script.
2019-12-06T00:18:55.859764+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-12-06T00:18:55.917128+00:00 app[web.1]:
2019-12-06T00:18:55.917132+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-12-06T00:18:55.917135+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-12-06T00_18_55_860Z-debug.log
2019-12-06T00:18:56.015418+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-06T00:18:55.990556+00:00 heroku[web.1]: Process exited with status 1
2019-12-06T00:18:57.272264+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=c-neri-heroku.herokuapp.com request_id=1371d608-aa3d-4ada-94bb-cde5f9edfd69 fwd="151.32.4.219" dyno= connect= service= status=503 bytes= protocol=https
2019-12-06T00:21:46.461037+00:00 heroku[web.1]: State changed from crashed to starting
2019-12-06T00:21:49.272673+00:00 heroku[web.1]: Starting process with command `npm start`
2019-12-06T00:21:53.501754+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-06T00:21:53.116284+00:00 app[web.1]:
2019-12-06T00:21:53.116306+00:00 app[web.1]: > 1-Heroku#1.0.0 start /app
2019-12-06T00:21:53.116308+00:00 app[web.1]: > node src/app.js
2019-12-06T00:21:53.116310+00:00 app[web.1]:
2019-12-06T00:21:53.306576+00:00 app[web.1]: internal/modules/cjs/loader.js:800
2019-12-06T00:21:53.306580+00:00 app[web.1]: throw err;
2019-12-06T00:21:53.306583+00:00 app[web.1]: ^
2019-12-06T00:21:53.306586+00:00 app[web.1]:
2019-12-06T00:21:53.306588+00:00 app[web.1]: Error: Cannot find module 'hbs'
2019-12-06T00:21:53.306591+00:00 app[web.1]: Require stack:
2019-12-06T00:21:53.306596+00:00 app[web.1]: - /app/src/app.js
2019-12-06T00:21:53.306598+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
2019-12-06T00:21:53.306600+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:690:27)
2019-12-06T00:21:53.306603+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:852:19)
2019-12-06T00:21:53.306605+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-12-06T00:21:53.306607+00:00 app[web.1]: at Object.<anonymous> (/app/src/app.js:5:13)
2019-12-06T00:21:53.306609+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:959:30)
2019-12-06T00:21:53.306611+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
2019-12-06T00:21:53.306613+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:815:32)
2019-12-06T00:21:53.306616+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:727:14)
2019-12-06T00:21:53.306618+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) {
2019-12-06T00:21:53.306620+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2019-12-06T00:21:53.306622+00:00 app[web.1]: requireStack: [ '/app/src/app.js' ]
2019-12-06T00:21:53.306624+00:00 app[web.1]: }
2019-12-06T00:21:53.321267+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-12-06T00:21:53.321742+00:00 app[web.1]: npm ERR! errno 1
2019-12-06T00:21:53.324564+00:00 app[web.1]: npm ERR! 1-Heroku#1.0.0 start: `node src/app.js`
2019-12-06T00:21:53.324972+00:00 app[web.1]: npm ERR! Exit status 1
2019-12-06T00:21:53.325528+00:00 app[web.1]: npm ERR!
2019-12-06T00:21:53.326031+00:00 app[web.1]: npm ERR! Failed at the 1-Heroku#1.0.0 start script.
2019-12-06T00:21:53.326436+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-12-06T00:21:53.342561+00:00 app[web.1]:
2019-12-06T00:21:53.342869+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-12-06T00:21:53.343077+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-12-06T00_21_53_327Z-debug.log
2019-12-06T00:21:53.479134+00:00 heroku[web.1]: Process exited with status 1
2019-12-06T00:22:24.106302+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=c-neri-heroku.herokuapp.com request_id=fbd6f731-b6f7-49c1-b1ed-2373fd79d7d1 fwd="151.32.4.219" dyno= connect= service= status=503 bytes= protocol=https
2019-12-06T00:31:08.844509+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=c-neri-heroku.herokuapp.com request_id=f109e557-116b-4915-8c50-82520f635a42 fwd="151.32.4.219" dyno= connect= service= status=503 bytes= protocol=https
my app.js
const express = require('express')
const path = require('path')
const app = express()
const appRoute = require('./routes/app.js')
const hbs = require( 'hbs')
const port = process.env.PORT||3001
const publicPath = path.join(__dirname + '../../public')
const partialsPath = path.join(__dirname + '/template/partials')
const viewPath = path.join(__dirname + '/template/views')
//HBS
app.set('view engine', 'hbs')
app.set('views', viewPath)
hbs.registerPartials(partialsPath)
app.use(express.static(publicPath))
//ROUTES
app.use(appRoute)
app.listen(port)
my package.js script
"scripts": {
"build": "webpack",
"watch": "webpack --watch",
"dev": "nodemon src/app.js",
"start": "node src/app.js"
},
I am a newbie in heroku and node.js and I would like to get to know how these work. I tried the tutorial given by heroku. Everthing is fine until this step. I pushed and tried to open in on the web, but doesn't work. Logs said it cannot find the module, meanwhile I've installed it using npm.
I tried 3 times using different new clone but nonetheless none worked. I also copied all the index.js script given on the tutorial.
index:
const cool = require('cool-ascii-faces')
const express = require('express')
const path = require('path')
const PORT = process.env.PORT || 5000
express()
.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
.get('/', (req, res) => res.render('pages/index'))
.get('/cool', (req, res) => res.send(cool()))
.listen(PORT, () => console.log(`Listening on ${ PORT }`))
logs:
2019-05-09T09:56:08.000000+00:00 app[api]: Build succeeded
2019-05-09T09:56:08.892352+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-05-09T09:56:08.986034+00:00 heroku[web.1]: Process exited with status 143
2019-05-09T09:56:09.884923+00:00 heroku[web.1]: Starting process with command `node index.js`
2019-05-09T09:56:11.789509+00:00 heroku[web.1]: State changed from starting to crashed
2019-05-09T09:56:11.800910+00:00 heroku[web.1]: State changed from crashed to starting
2019-05-09T09:56:11.773890+00:00 heroku[web.1]: Process exited with status 1
2019-05-09T09:56:11.731995+00:00 app[web.1]: internal/modules/cjs/loader.js:584
2019-05-09T09:56:11.732041+00:00 app[web.1]: throw err;
2019-05-09T09:56:11.732043+00:00 app[web.1]: ^
2019-05-09T09:56:11.732044+00:00 app[web.1]:
2019-05-09T09:56:11.732045+00:00 app[web.1]: Error: Cannot find module 'cool-ascii-faces'
2019-05-09T09:56:11.732047+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
2019-05-09T09:56:11.732048+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:508:25)
2019-05-09T09:56:11.732049+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-05-09T09:56:11.732050+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)
2019-05-09T09:56:11.732052+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:1:76)
2019-05-09T09:56:11.732053+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)
2019-05-09T09:56:11.732054+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
2019-05-09T09:56:11.732055+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)
2019-05-09T09:56:11.732056+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
2019-05-09T09:56:11.732058+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:531:3)
2019-05-09T09:56:14.928577+00:00 heroku[web.1]: Starting process with command `node index.js`
2019-05-09T09:56:17.311684+00:00 heroku[web.1]: State changed from starting to crashed
2019-05-09T09:56:17.291125+00:00 heroku[web.1]: Process exited with status 1
2019-05-09T09:56:17.224570+00:00 app[web.1]: internal/modules/cjs/loader.js:584
2019-05-09T09:56:17.224594+00:00 app[web.1]: throw err;
2019-05-09T09:56:17.224596+00:00 app[web.1]: ^
2019-05-09T09:56:17.224598+00:00 app[web.1]:
2019-05-09T09:56:17.224600+00:00 app[web.1]: Error: Cannot find module 'cool-ascii-faces'
2019-05-09T09:56:17.224601+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
2019-05-09T09:56:17.224603+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:508:25)
2019-05-09T09:56:17.224605+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-05-09T09:56:17.224609+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)
2019-05-09T09:56:17.224610+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:1:76)
2019-05-09T09:56:17.224612+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)
2019-05-09T09:56:17.224614+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
2019-05-09T09:56:17.224615+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)
2019-05-09T09:56:17.224617+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
2019-05-09T09:56:17.224618+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:531:3)
2019-05-09T09:56:19.017142+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/cool" host=immense-oasis-20574.herokuapp.com request_id=b24f9916-5042-4b41-9034-e5421063b37f fwd="87.187.232.81" dyno= connect= service= status=503 bytes= protocol=https
2019-05-09T10:09:56.847796+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=immense-oasis-20574.herokuapp.com request_id=62b8f104-be58-49f5-9b45-82603b0cc1a9 fwd="87.187.232.81" dyno= connect= service= status=503 bytes= protocol=https
You have to run npm install --save cool-ascii-faces.
Heroku get the packages from your package.json and not from the node_modules folder. You should actually never commit it by adding it to your .gitignore file.
I have now spent a couple of days searching for reasons why this is happening and have tried to make sure all file names are consistent both locally and in the git push since I hear that Heroku can be funny about this.
The app works absolutely fine on my local server I should add.
Here is the heroku logs coming from when I restart the app on heroku:
2019-03-04T21:42:46.527650+00:00 heroku[web.1]: State changed from crashed to starting
2019-03-04T21:42:49.314540+00:00 heroku[web.1]: Starting process with command `node index.js`
2019-03-04T21:42:50.921757+00:00 app[web.1]: { NODE_HOME: '/app/.heroku/node',
2019-03-04T21:42:50.921775+00:00 app[web.1]: NODE_ENV: 'production',
2019-03-04T21:42:50.921776+00:00 app[web.1]: WEB_MEMORY: '512',
2019-03-04T21:42:50.921777+00:00 app[web.1]: DYNO: 'web.1',
2019-03-04T21:42:50.921779+00:00 app[web.1]: PWD: '/app',
2019-03-04T21:42:50.921780+00:00 app[web.1]: HOME: '/app',
2019-03-04T21:42:50.921781+00:00 app[web.1]: PORT: '51817',
2019-03-04T21:42:50.921782+00:00 app[web.1]: MEMORY_AVAILABLE: '512',
2019-03-04T21:42:50.921783+00:00 app[web.1]: WEB_CONCURRENCY: '1',
2019-03-04T21:42:50.921784+00:00 app[web.1]: SHLVL: '1',
2019-03-04T21:42:50.921785+00:00 app[web.1]: PATH:
2019-03-04T21:42:50.921787+00:00 app[web.1]: '/app/.heroku/node/bin:/app/.heroku/yarn/bin:/usr/local/bin:/usr/bin:/bin:/app/bin:/app/node_modules/.bin',
2019-03-04T21:42:50.921788+00:00 app[web.1]: PS1:
2019-03-04T21:42:50.921790+00:00 app[web.1]: '\\[\\033[01;34m\\]\\w\\[\\033[00m\\] \\[\\033[01;32m\\]$ \\[\\033[00m\\]',
2019-03-04T21:42:50.921791+00:00 app[web.1]: _: '/app/.heroku/node/bin/node',
2019-03-04T21:42:50.921792+00:00 app[web.1]: COUDINARY_NAME: 'djbcg1deo',
2019-03-04T21:42:50.921793+00:00 app[web.1]: COUDINARY_API_KEY: '571183338823141',
2019-03-04T21:42:50.921794+00:00 app[web.1]: COUDINARY_API_SECRET: 'DkJ_3UsH7DLTsHHwmD68AMUYJzY',
2019-03-04T21:42:50.921795+00:00 app[web.1]: DB_URI: 'node-js-blog' }
2019-03-04T21:42:51.723033+00:00 app[web.1]: internal/modules/cjs/loader.js:582
2019-03-04T21:42:51.723058+00:00 app[web.1]: throw err;
2019-03-04T21:42:51.723060+00:00 app[web.1]: ^
2019-03-04T21:42:51.723061+00:00 app[web.1]:
2019-03-04T21:42:51.723063+00:00 app[web.1]: Error: Cannot find module './controllers/createPost'
2019-03-04T21:42:51.723066+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
2019-03-04T21:42:51.723068+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:506:25)
2019-03-04T21:42:51.723069+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:636:17)
2019-03-04T21:42:51.723071+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:20:18)
2019-03-04T21:42:51.723073+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:14:30)
2019-03-04T21:42:51.723074+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2019-03-04T21:42:51.723076+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2019-03-04T21:42:51.723078+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2019-03-04T21:42:51.723079+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
2019-03-04T21:42:51.723081+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:529:3)
2019-03-04T21:42:51.723082+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
2019-03-04T21:42:51.723084+00:00 app[web.1]: at startup (internal/bootstrap/node.js:285:19)
2019-03-04T21:42:51.723086+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
2019-03-04T21:42:51.789482+00:00 heroku[web.1]: State changed from starting to crashed
2019-03-04T21:42:51.770169+00:00 heroku[web.1]: Process exited with status 1
2019-03-04T21:43:12.736446+00:00 heroku[run.9030]: Client connection closed. Sending SIGHUP to all processes
2019-03-04T21:43:13.319723+00:00 heroku[run.9030]: State changed from up to complete
2019-03-04T21:43:13.297680+00:00 heroku[run.9030]: Process exited with status 129
2019-03-04T21:43:16.063306+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=james-node-blog.herokuapp.com request_id=b16a486a-239e-4bc4-9673-4f24febd9265 fwd="82.6.200.12" dyno= connect= service= status=503 bytes= protocol=https
2019-03-04T21:43:17.018561+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=james-node-blog.herokuapp.com request_id=63cc1508-3943-4251-b424-674186d84e76 fwd="82.6.200.12" dyno= connect= service= status=503 bytes= protocol=https
Also, the code can be found on my Github repo here:
https://github.com/jameslevine/Nodejs-Blog
I would greatly appreciate some pointers if anyone has any since I am going round in circles at this point.
Thanks in advance!
Update: Resolved 2 errors. First one was the filename change and the second was the fact that .gitignore didn't include the node_modules file. Now app gives this log, which indicates it is no longer crashing. However, I still can't see the app by clicking on Live App on Heroku. Any help there?
I have included logs below:
2019-03-05T08:59:41.441061+00:00 heroku[web.1]: Restarting
2019-03-05T08:59:41.444978+00:00 heroku[web.1]: State changed from up to starting
2019-03-05T08:59:42.400893+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-03-05T08:59:42.520869+00:00 heroku[web.1]: Process exited with status 143
2019-03-05T08:59:43.970483+00:00 heroku[web.1]: Starting process with command `node index.js`
2019-03-05T08:59:45.929838+00:00 app[web.1]: { NODE_HOME: '/app/.heroku/node',
2019-03-05T08:59:45.929860+00:00 app[web.1]: NODE_ENV: 'production',
2019-03-05T08:59:45.929862+00:00 app[web.1]: WEB_MEMORY: '512',
2019-03-05T08:59:45.929863+00:00 app[web.1]: DYNO: 'web.1',
2019-03-05T08:59:45.929865+00:00 app[web.1]: PWD: '/app',
2019-03-05T08:59:45.929867+00:00 app[web.1]: HOME: '/app',
2019-03-05T08:59:45.929868+00:00 app[web.1]: PORT: '54093',
2019-03-05T08:59:45.929869+00:00 app[web.1]: MEMORY_AVAILABLE: '512',
2019-03-05T08:59:45.929870+00:00 app[web.1]: WEB_CONCURRENCY: '1',
2019-03-05T08:59:45.929871+00:00 app[web.1]: SHLVL: '1',
2019-03-05T08:59:45.929873+00:00 app[web.1]: PATH:
2019-03-05T08:59:45.929874+00:00 app[web.1]: '/app/.heroku/node/bin:/app/.heroku/yarn/bin:/usr/local/bin:/usr/bin:/bin:/app/bin:/app/node_modules/.bin',
2019-03-05T08:59:45.929875+00:00 app[web.1]: PS1:
2019-03-05T08:59:45.929877+00:00 app[web.1]: '\\[\\033[01;34m\\]\\w\\[\\033[00m\\] \\[\\033[01;32m\\]$ \\[\\033[00m\\]',
2019-03-05T08:59:45.929878+00:00 app[web.1]: _: '/app/.heroku/node/bin/node',
2019-03-05T08:59:45.929879+00:00 app[web.1]: COUDINARY_NAME: 'djbcg1deo',
2019-03-05T08:59:45.929880+00:00 app[web.1]: COUDINARY_API_KEY: '571183338823141',
2019-03-05T08:59:45.929881+00:00 app[web.1]: COUDINARY_API_SECRET: 'DkJ_3UsH7DLTsHHwmD68AMUYJzY',
2019-03-05T08:59:45.929882+00:00 app[web.1]: DB_URI: 'node-js-blog' }
2019-03-05T08:59:46.787139+00:00 app[web.1]: Tue, 05 Mar 2019 08:59:46 GMT express-session deprecated undefined resave option; provide resave option at index.js:38:9
2019-03-05T08:59:46.787355+00:00 app[web.1]: Tue, 05 Mar 2019 08:59:46 GMT express-session deprecated undefined saveUninitialized option; provide saveUninitialized option at index.js:38:9
2019-03-05T08:59:46.795789+00:00 app[web.1]: (node:4) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2019-03-05T08:59:46.796700+00:00 app[web.1]: App listing on port 54093
2019-03-05T08:59:46.804363+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
2019-03-05T08:59:46.804367+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:564:11)
2019-03-05T08:59:46.804369+00:00 app[web.1]: at Pool.emit (events.js:182:13)
2019-03-05T08:59:46.804370+00:00 app[web.1]: at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:317:12)
2019-03-05T08:59:46.804372+00:00 app[web.1]: at Object.onceWrapper (events.js:273:13)
2019-03-05T08:59:46.804373+00:00 app[web.1]: at Connection.emit (events.js:182:13)
2019-03-05T08:59:46.804375+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:246:50)
2019-03-05T08:59:46.804377+00:00 app[web.1]: at Object.onceWrapper (events.js:273:13)
2019-03-05T08:59:46.804378+00:00 app[web.1]: at Socket.emit (events.js:182:13)
2019-03-05T08:59:46.804380+00:00 app[web.1]: at emitErrorNT (internal/streams/destroy.js:82:8)
2019-03-05T08:59:46.804382+00:00 app[web.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
2019-03-05T08:59:46.804384+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2019-03-05T08:59:46.804474+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
2019-03-05T08:59:46.804552+00:00 app[web.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2019-03-05T08:59:47.581487+00:00 heroku[web.1]: State changed from starting to up
2019-03-05T09:00:21.698023+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=james-node-blog.herokuapp.com request_id=55c8cc21-6544-4e4c-800f-62eac6ed8034 fwd="62.30.226.42" dyno=web.1 connect=2ms service=30000ms status=503 bytes=0 protocol=https
2019-03-05T09:01:18.887286+00:00 heroku[router]: at=error code=H15 desc="Idle connection" method=GET path="/favicon.ico" host=james-node-blog.herokuapp.com request_id=ccfeba5b-3105-423c-87f6-edfe9ba86584 fwd="62.30.226.42" dyno=web.1 connect=1ms service=55036ms status=503 bytes= protocol=https
Any ideas why it is now not showing live? I am just beginning to research this and think it is something to do with the server not starting but thought I would update on progress as I go along.
I think it's just a typo, you're trying to require createPost in index.js:14 and the file is actually called createpost.js
Error: Cannot find module './controllers/createPost'
It's weird, though, that it's working locally.
I wrote a simple NodeJs web app using React. I use Socket.io in this app to connect client to the server. The following codes are for my server.js and the component which connects to the server :
Server.js :
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var index = require('./routes/index');
var socket = require('./common/socket');
var exphbs = require('express-handlebars');
var app = express();
require('node-jsx').install();
var port = process.env.PORT || 9091;
var io = require('socket.io').listen(app.listen(port, function(){
console.log('Server is listening on port: ' + port);
}));
io.sockets.on('connection', function(sock){
socket(sock , io);
});
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
// view engine setup
app.engine('handlebars', exphbs({defaultLayout: 'main', extname: '.handlebars'}));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'handlebars');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
console.log(err.message);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
Component.js :
'use strict';
var React = require('react');
var io = require('socket.io-client');
var socket;
var UserRow = require('./userRow');
var SimpleUserList = React.createClass({
displayName: 'SimpleUserList',
componentDidMount: function() {
socket = io.connect();
socket.on('userList', function(data) {
console.log('userlist received');
}.bind(this));
},
componentWillUnmount: function() {
socket.close();
},
render: function() {
return (<div></div>);
}
module.exports = SimpleUserList;
main.handlebars :
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="stylesheets/style.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
{{{ body }}}
<script src="https://cdn.socket.io/socket.io-1.0.0.js"></script>
<script src="javascripts/bundle.js"></script>
</body>
</html>
The handle bar is not important, I just wanted to show what script file I include in my html file.
Any idea why I cannot connect to the heroku server?
heroku log :
2015-07-29T10:59:30.153481+00:00 app[web.1]: > npm run-script build | node server.js
2015-07-29T10:59:30.153482+00:00 app[web.1]:
2015-07-29T10:59:39.356552+00:00 app[web.1]: /app/server.js:22
2015-07-29T10:59:39.356556+00:00 app[web.1]: io.configure(function () {
2015-07-29T10:59:39.356558+00:00 app[web.1]: ^
2015-07-29T10:59:39.356560+00:00 app[web.1]: TypeError: undefined is not a function
2015-07-29T10:59:39.356561+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:22:4)
2015-07-29T10:59:39.356565+00:00 app[web.1]: at Object.Module._extensions..js (module.js:478:10)
2015-07-29T10:59:39.356590+00:00 app[web.1]: at Module.load (module.js:355:32)
2015-07-29T10:59:39.356595+00:00 app[web.1]: at startup (node.js:129:16)
2015-07-29T10:59:39.356563+00:00 app[web.1]: at Module._compile (module.js:460:26)
2015-07-29T10:59:39.356593+00:00 app[web.1]: at Function.Module.runMain (module.js:501:10)
2015-07-29T10:59:39.356596+00:00 app[web.1]: at node.js:814:3
2015-07-29T10:59:39.356592+00:00 app[web.1]: at Function.Module._load (module.js:310:12)
2015-07-29T10:59:44.937645+00:00 app[web.1]: npm ERR! Linux 3.13.0-49-generic
2015-07-29T10:59:44.817354+00:00 app[web.1]: util.print: Use console.log instead
2015-07-29T10:59:44.932214+00:00 app[web.1]:
2015-07-29T10:59:44.938157+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2015-07-29T10:59:44.938399+00:00 app[web.1]: npm ERR! node v0.12.7
2015-07-29T10:59:44.938826+00:00 app[web.1]: npm ERR! npm v2.11.3
2015-07-29T10:59:44.939022+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2015-07-29T10:59:44.939233+00:00 app[web.1]: npm ERR! simple-user-list#0.0.0 start: `npm run-script build | node server.js `
2015-07-29T10:59:44.939499+00:00 app[web.1]: npm ERR! Exit status 1
2015-07-29T10:59:44.939661+00:00 app[web.1]: npm ERR!
2015-07-29T10:59:44.939844+00:00 app[web.1]: npm ERR! Failed at the simple-user-list#0.0.0 start script 'npm run-script build | node server.js '.
2015-07-29T10:59:44.940270+00:00 app[web.1]: npm ERR! This is most likely a problem with the simple-user-list package,
2015-07-29T10:59:44.940497+00:00 app[web.1]: npm ERR! not with npm itself.
2015-07-29T10:59:44.940649+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2015-07-29T10:59:44.940834+00:00 app[web.1]: npm ERR! npm run-script build | node server.js
2015-07-29T10:59:44.940988+00:00 app[web.1]: npm ERR! You can get their info via:
2015-07-29T10:59:44.941492+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2015-07-29T10:59:44.944584+00:00 app[web.1]:
2015-07-29T10:59:44.941149+00:00 app[web.1]: npm ERR! npm owner ls simple-user-list
2015-07-29T10:59:44.944830+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2015-07-29T10:59:44.944952+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2015-07-29T10:59:45.817817+00:00 heroku[web.1]: Process exited with status 1
2015-07-29T10:59:45.831953+00:00 heroku[web.1]: State changed from starting to crashed
2015-07-29T10:59:47.593870+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=bd0cf3d6-0b8b-4fc0-aa37-a940cd5f328f fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T10:59:57.607136+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=8f80ec43-0eb8-4375-9341-7c1c2ecb81f0 fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T11:00:07.626517+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=4ee95d7b-e757-4590-b9e9-f48f491a3654 fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T11:00:17.650806+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=bdebebe0-6b5b-444b-81f2-fb34d3b00bb4 fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T11:00:27.660163+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=289949c3-1dac-4f3c-bb89-f6093da2c997 fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T11:00:37.669828+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=997d267f-81fb-40e4-9c7d-85f9803653f8 fwd="50.19.169.132" dyno= connect= service= status=503 bytes=
2015-07-29T11:06:28.718078+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=simple-user-list.herokuapp.com request_id=c0f10a34-914a-439b-8a59-5ef954d994e8 fwd="207.6.39.42" dyno= connect= service= status=503 bytes=
2015-07-29T11:10:46.273821+00:00 heroku[web.1]: State changed from crashed to starting
2015-07-29T11:10:49.577787+00:00 heroku[web.1]: Starting process with command `npm start`
2015-07-29T11:10:51.591809+00:00 app[web.1]:
2015-07-29T11:10:51.591830+00:00 app[web.1]: > simple-user-list#0.0.0 start /app
2015-07-29T11:10:51.591832+00:00 app[web.1]: > npm run-script build | node server.js
2015-07-29T11:10:51.591833+00:00 app[web.1]:
2015-07-29T11:10:57.340680+00:00 app[web.1]: /app/server.js:22
2015-07-29T11:10:57.340683+00:00 app[web.1]: io.configure(function () {
2015-07-29T11:10:57.340685+00:00 app[web.1]: ^
2015-07-29T11:10:57.340687+00:00 app[web.1]: TypeError: undefined is not a function
2015-07-29T11:10:57.340689+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:22:4)
2015-07-29T11:10:57.340692+00:00 app[web.1]: at Object.Module._extensions..js (module.js:478:10)
2015-07-29T11:10:57.340693+00:00 app[web.1]: at Module.load (module.js:355:32)
2015-07-29T11:10:57.340690+00:00 app[web.1]: at Module._compile (module.js:460:26)
2015-07-29T11:10:57.340695+00:00 app[web.1]: at Function.Module._load (module.js:310:12)
2015-07-29T11:10:57.340696+00:00 app[web.1]: at Function.Module.runMain (module.js:501:10)
2015-07-29T11:10:57.340697+00:00 app[web.1]: at startup (node.js:129:16)
2015-07-29T11:10:57.340699+00:00 app[web.1]: at node.js:814:3
2015-07-29T11:11:02.957215+00:00 app[web.1]: util.print: Use console.log instead
2015-07-29T11:11:03.080961+00:00 app[web.1]: npm ERR! Linux 3.13.0-57-generic
2015-07-29T11:11:03.088435+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2015-07-29T11:11:03.088566+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2015-07-29T11:11:03.074299+00:00 app[web.1]:
2015-07-29T11:11:03.081974+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2015-07-29T11:11:03.082248+00:00 app[web.1]: npm ERR! node v0.12.7
2015-07-29T11:11:03.082698+00:00 app[web.1]: npm ERR! npm v2.11.3
2015-07-29T11:11:03.082883+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2015-07-29T11:11:03.083205+00:00 app[web.1]: npm ERR! simple-user-list#0.0.0 start: `npm run-script build | node server.js `
2015-07-29T11:11:03.083354+00:00 app[web.1]: npm ERR! Exit status 1
2015-07-29T11:11:03.083515+00:00 app[web.1]: npm ERR!
2015-07-29T11:11:03.083669+00:00 app[web.1]: npm ERR! Failed at the simple-user-list#0.0.0 start script 'npm run-script build | node server.js '.
2015-07-29T11:11:03.084247+00:00 app[web.1]: npm ERR! not with npm itself.
2015-07-29T11:11:03.084376+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2015-07-29T11:11:03.083969+00:00 app[web.1]: npm ERR! This is most likely a problem with the simple-user-list package,
2015-07-29T11:11:03.085055+00:00 app[web.1]: npm ERR! You can get their info via:
2015-07-29T11:11:03.084565+00:00 app[web.1]: npm ERR! npm run-script build | node server.js
2015-07-29T11:11:03.085058+00:00 app[web.1]: npm ERR! npm owner ls simple-user-list
2015-07-29T11:11:03.085128+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2015-07-29T11:11:03.088091+00:00 app[web.1]:
2015-07-29T11:11:03.853402+00:00 heroku[web.1]: Process exited with status 1
2015-07-29T11:11:03.866414+00:00 heroku[web.1]: State changed from starting to crashed
2015-07-29T11:16:15.196180+00:00 heroku[slug-compiler]: Slug compilation started
2015-07-29T11:16:15.196195+00:00 heroku[slug-compiler]: Slug compilation finished
2015-07-29T11:16:15.153339+00:00 heroku[api]: Deploy a6fb15c by aryan.hosseinzadeh#gmail.com
2015-07-29T11:16:15.153339+00:00 heroku[api]: Release v15 created by aryan.hosseinzadeh#gmail.com
2015-07-29T11:16:15.571381+00:00 heroku[web.1]: State changed from crashed to starting
2015-07-29T11:16:19.908038+00:00 heroku[web.1]: Starting process with command `npm start`
2015-07-29T11:16:22.344144+00:00 app[web.1]:
2015-07-29T11:16:22.344166+00:00 app[web.1]: > simple-user-list#0.0.0 start /app
2015-07-29T11:16:22.344168+00:00 app[web.1]: > npm run-script build | node server.js
2015-07-29T11:16:22.344170+00:00 app[web.1]:
2015-07-29T11:16:28.997464+00:00 app[web.1]: Option polling duration is not valid. Please refer to the README.
2015-07-29T11:16:29.378774+00:00 heroku[web.1]: State changed from starting to up
2015-07-29T11:16:29.671752+00:00 app[web.1]: Server is listening on port: 9807
2015-07-29T11:16:30.880399+00:00 heroku[router]: at=info method=GET path="/" host=simple-user-list.herokuapp.com request_id=8286e365-9790-487e-9b71-a69a4de800fc fwd="54.144.80.213" dyno=web.1 connect=6ms service=227ms status=200 bytes=2017
2015-07-29T11:16:30.910262+00:00 app[web.1]: GET / 200 252.009 ms - 1821
2015-07-29T11:16:34.120554+00:00 app[web.1]: util.print: Use console.log instead
So , it's solved.
There was no need to explicitly refer to {host}/socket/socket.io and there was no need to specify io.config (at least so far) and also there was no need to specify host address on client side (io.connect is good enough).