ReferenceError: require is not defined when I push on Heroku - node.js

I want to push my NodeJS project on heroku but it doesn't work while my project works fine locally.
When I enter "heroku logs --tail" to see errors, I see :
2020-08-18T10:39:44.396002+00:00 app[web.1]: const express = require('express')
2020-08-18T10:39:44.396003+00:00 app[web.1]: ^
2020-08-18T10:39:44.396003+00:00 app[web.1]:
2020-08-18T10:39:44.396004+00:00 app[web.1]: ReferenceError: require is not defined
This is my "index.js" :
const express = require('express')
if (process.env.NODE_ENV === 'dev') require('dotenv').config()
const routerIdeas = require('./routes/ideas.js')
const PORT = process.env.PORT || 5000
const app = express()
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
next()
})
app.use('/api', routerIdeas)
app.listen(PORT, () => {
console.log(`Server is running on port : ${PORT}`)
})
This is the complete "heroku logs --tail" :
server git:(master) heroku logs --tail
› Warning: heroku update available from 7.7.7 to 7.42.6
2020-08-18T10:17:04.311750+00:00 app[web.1]: (node:4) ExperimentalWarning: The ESM module loader is experimental.
2020-08-18T10:17:04.322224+00:00 app[web.1]: file:///app/index.js:1
2020-08-18T10:17:04.322225+00:00 app[web.1]: const express = require('express')
2020-08-18T10:17:04.322226+00:00 app[web.1]: ^
2020-08-18T10:17:04.322226+00:00 app[web.1]:
2020-08-18T10:17:04.322227+00:00 app[web.1]: ReferenceError: require is not defined
2020-08-18T10:17:04.322227+00:00 app[web.1]: at file:///app/index.js:1:17
2020-08-18T10:17:04.322228+00:00 app[web.1]: at ModuleJob.run (internal/modules/esm/module_job.js:139:37)
2020-08-18T10:17:04.322228+00:00 app[web.1]: at async Loader.import (internal/modules/esm/loader.js:179:24)
2020-08-18T10:17:04.372043+00:00 heroku[web.1]: Process exited with status 1
2020-08-18T10:17:04.401546+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-18T10:39:40.712443+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-18T10:39:42.672554+00:00 heroku[web.1]: Starting process with command `node index.js`
2020-08-18T10:39:44.381963+00:00 app[web.1]: (node:4) ExperimentalWarning: The ESM module loader is experimental.
2020-08-18T10:39:44.396000+00:00 app[web.1]: file:///app/index.js:1
2020-08-18T10:39:44.396002+00:00 app[web.1]: const express = require('express')
2020-08-18T10:39:44.396003+00:00 app[web.1]: ^
2020-08-18T10:39:44.396003+00:00 app[web.1]:
2020-08-18T10:39:44.396004+00:00 app[web.1]: ReferenceError: require is not defined
2020-08-18T10:39:44.396005+00:00 app[web.1]: at file:///app/index.js:1:17
2020-08-18T10:39:44.396005+00:00 app[web.1]: at ModuleJob.run (internal/modules/esm/module_job.js:139:37)
2020-08-18T10:39:44.396008+00:00 app[web.1]: at async Loader.import (internal/modules/esm/loader.js:179:24)
2020-08-18T10:39:44.439811+00:00 heroku[web.1]: Process exited with status 1
2020-08-18T10:39:44.472252+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-18T10:41:22.000000+00:00 app[api]: Build started by user mika77290#live.fr
2020-08-18T10:41:49.742104+00:00 app[api]: Release v6 created by user mika77290#live.fr
2020-08-18T10:41:49.742104+00:00 app[api]: Deploy 36bf1d35 by user mika77290#live.fr
2020-08-18T10:41:50.000000+00:00 app[api]: Build succeeded
2020-08-18T10:41:50.965669+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-18T10:41:53.104246+00:00 heroku[web.1]: Starting process with command `node index.js`
2020-08-18T10:41:54.814879+00:00 app[web.1]: (node:4) ExperimentalWarning: The ESM module loader is experimental.
2020-08-18T10:41:54.832290+00:00 app[web.1]: file:///app/index.js:1
2020-08-18T10:41:54.832292+00:00 app[web.1]: const express = require('express')
2020-08-18T10:41:54.832292+00:00 app[web.1]: ^
2020-08-18T10:41:54.832293+00:00 app[web.1]:
2020-08-18T10:41:54.832294+00:00 app[web.1]: ReferenceError: require is not defined
2020-08-18T10:41:54.832294+00:00 app[web.1]: at file:///app/index.js:1:17
2020-08-18T10:41:54.832294+00:00 app[web.1]: at ModuleJob.run (internal/modules/esm/module_job.js:139:37)
2020-08-18T10:41:54.832295+00:00 app[web.1]: at async Loader.import (internal/modules/esm/loader.js:179:24)
2020-08-18T10:41:54.882959+00:00 heroku[web.1]: Process exited with status 1
2020-08-18T10:41:54.911539+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-18T10:41:57.989717+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=exercice-ideas.herokuapp.com request_id=909d0f01-935e-4d95-bbf0-80e745d61559 fwd="81.249.233.246" dyno= connect= service= status=503 bytes= protocol=https
2020-08-18T10:42:08.284424+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/api/ideas" host=exercice-ideas.herokuapp.com request_id=011b8593-6112-48a0-aa6e-d4c7ab5051b5 fwd="81.249.233.246" dyno= connect= service= status=503 bytes= protocol=https
2020-08-18T10:52:39.587775+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-18T10:52:41.637962+00:00 heroku[web.1]: Starting process with command `node index.js`
2020-08-18T10:52:43.235694+00:00 app[web.1]: (node:4) ExperimentalWarning: The ESM module loader is experimental.
2020-08-18T10:52:43.250839+00:00 app[web.1]: file:///app/index.js:1
2020-08-18T10:52:43.250841+00:00 app[web.1]: const express = require('express')
2020-08-18T10:52:43.250846+00:00 app[web.1]: ^
2020-08-18T10:52:43.250846+00:00 app[web.1]:
2020-08-18T10:52:43.250847+00:00 app[web.1]: ReferenceError: require is not defined
2020-08-18T10:52:43.250847+00:00 app[web.1]: at file:///app/index.js:1:17
2020-08-18T10:52:43.250848+00:00 app[web.1]: at ModuleJob.run (internal/modules/esm/module_job.js:139:37)
2020-08-18T10:52:43.250848+00:00 app[web.1]: at async Loader.import (internal/modules/esm/loader.js:179:24)
2020-08-18T10:52:43.292178+00:00 heroku[web.1]: Process exited with status 1
2020-08-18T10:52:43.323908+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-18T11:15:25.594409+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-18T11:15:28.438563+00:00 heroku[web.1]: Starting process with command `node index.js`
2020-08-18T11:15:30.865146+00:00 app[web.1]: (node:4) ExperimentalWarning: The ESM module loader is experimental.
2020-08-18T11:15:30.883077+00:00 app[web.1]: file:///app/index.js:1
2020-08-18T11:15:30.883079+00:00 app[web.1]: const express = require('express')
2020-08-18T11:15:30.883080+00:00 app[web.1]: ^
2020-08-18T11:15:30.883081+00:00 app[web.1]:
2020-08-18T11:15:30.883081+00:00 app[web.1]: ReferenceError: require is not defined
2020-08-18T11:15:30.883081+00:00 app[web.1]: at file:///app/index.js:1:17
2020-08-18T11:15:30.883082+00:00 app[web.1]: at ModuleJob.run (internal/modules/esm/module_job.js:139:37)
2020-08-18T11:15:30.883083+00:00 app[web.1]: at async Loader.import (internal/modules/esm/loader.js:179:24)
2020-08-18T11:15:30.934853+00:00 heroku[web.1]: Process exited with status 1
2020-08-18T11:15:30.968511+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-18T11:33:00.000000+00:00 app[api]: Build started by user mika77290#live.fr
2020-08-18T11:33:34.000000+00:00 app[api]: Build succeeded
2020-08-18T11:33:34.073417+00:00 app[api]: Release v7 created by user mika77290#live.fr
2020-08-18T11:33:34.073417+00:00 app[api]: Deploy f5b59800 by user mika77290#live.fr
2020-08-18T11:33:35.255435+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-18T11:33:37.308185+00:00 heroku[web.1]: Starting process with command `node index.js`
2020-08-18T11:33:39.745180+00:00 app[web.1]: (node:4) ExperimentalWarning: The ESM module loader is experimental.
2020-08-18T11:33:39.758881+00:00 app[web.1]: file:///app/index.js:21
2020-08-18T11:33:39.758883+00:00 app[web.1]: const express = require('express')
2020-08-18T11:33:39.758884+00:00 app[web.1]: ^
2020-08-18T11:33:39.758884+00:00 app[web.1]:
2020-08-18T11:33:39.758885+00:00 app[web.1]: ReferenceError: require is not defined
2020-08-18T11:33:39.758885+00:00 app[web.1]: at file:///app/index.js:21:17
2020-08-18T11:33:39.758885+00:00 app[web.1]: at ModuleJob.run (internal/modules/esm/module_job.js:139:37)
2020-08-18T11:33:39.758886+00:00 app[web.1]: at async Loader.import (internal/modules/esm/loader.js:179:24)
2020-08-18T11:33:39.804994+00:00 heroku[web.1]: Process exited with status 1
2020-08-18T11:33:39.836710+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-18T11:33:39.838855+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-18T11:33:41.998743+00:00 heroku[web.1]: Starting process with command `node index.js`
2020-08-18T11:33:44.652533+00:00 app[web.1]: (node:4) ExperimentalWarning: The ESM module loader is experimental.
2020-08-18T11:33:44.674413+00:00 app[web.1]: file:///app/index.js:21
2020-08-18T11:33:44.674415+00:00 app[web.1]: const express = require('express')
2020-08-18T11:33:44.674415+00:00 app[web.1]: ^
2020-08-18T11:33:44.674416+00:00 app[web.1]:
2020-08-18T11:33:44.674416+00:00 app[web.1]: ReferenceError: require is not defined
2020-08-18T11:33:44.674417+00:00 app[web.1]: at file:///app/index.js:21:17
2020-08-18T11:33:44.674417+00:00 app[web.1]: at ModuleJob.run (internal/modules/esm/module_job.js:139:37)
2020-08-18T11:33:44.674418+00:00 app[web.1]: at async Loader.import (internal/modules/esm/loader.js:179:24)
2020-08-18T11:33:44.736273+00:00 heroku[web.1]: Process exited with status 1
2020-08-18T11:33:44.780957+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-18T11:33:46.586184+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=exercice-ideas.herokuapp.com request_id=af66c9bb-71fb-4575-a9b2-856ef0fd7c92 fwd="81.249.233.246" dyno= connect= service= status=503 bytes= protocol=https
I tried pushing the test project provided on the Heroku starter tutorial and there is no problem with "require", so I don't understand.
Thank you in advance to whoever can help me

I had same problem and what I did was in the package.json file I removed type:module and it worked.

I have deleted the '.git' and 'Procfile' file.
I also delete the repository on Heroku and create a new one.
I then start the procedure again to link my project to the new repository.
Then I pushed the project and now there are no more errors.
I don't understand why but it works now.

Related

App works locally but getteting error on heroku

I'm working on an amazon clone app from a turorial. It works locally and it will deploy to heroku with no errors but I get a Module Not Found for the productsController.
The file structure is
├── backend
| ├── config
│ ├── controllers
│ │ ├── productController.js
│ ├── models
│ ├── routes
│ │ ├── productRoutes.js
│ ├── server.js
Here is the heroku error log:
2023-01-06T01:09:09.693860+00:00 app[web.1]: ^
2023-01-06T01:09:09.693860+00:00 app[web.1]:
2023-01-06T01:09:09.693861+00:00 app[web.1]: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/backend/controllers/productController.js' imported from /app/backend/routes/productRoutes.js
2023-01-06T01:09:09.693861+00:00 app[web.1]: at new NodeError (node:internal/errors:393:5)
2023-01-06T01:09:09.693862+00:00 app[web.1]: at finalizeResolution (node:internal/modules/esm/resolve:323:11)
2023-01-06T01:09:09.693862+00:00 app[web.1]: at moduleResolve (node:internal/modules/esm/resolve:916:10)
2023-01-06T01:09:09.693862+00:00 app[web.1]: at defaultResolve (node:internal/modules/esm/resolve:1124:11)
2023-01-06T01:09:09.693863+00:00 app[web.1]: at nextResolve (node:internal/modules/esm/loader:163:28)
2023-01-06T01:09:09.693863+00:00 app[web.1]: at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
2023-01-06T01:09:09.693863+00:00 app[web.1]: at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
2023-01-06T01:09:09.693864+00:00 app[web.1]: at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
2023-01-06T01:09:09.693875+00:00 app[web.1]: at link (node:internal/modules/esm/module_job:75:36) {
2023-01-06T01:09:09.693875+00:00 app[web.1]: code: 'ERR_MODULE_NOT_FOUND'
2023-01-06T01:09:09.693875+00:00 app[web.1]: }
2023-01-06T01:09:09.693880+00:00 app[web.1]:
2023-01-06T01:09:09.693880+00:00 app[web.1]: Node.js v18.12.1
2023-01-06T01:09:09.881953+00:00 heroku[web.1]: Process exited with status 1
2023-01-06T01:09:09.926097+00:00 heroku[web.1]: State changed from starting to crashed
2023-01-06T01:09:09.936162+00:00 heroku[web.1]: State changed from crashed to starting
2023-01-06T01:09:18.922072+00:00 heroku[web.1]: Starting process with command `npm start`
2023-01-06T01:09:20.986680+00:00 app[web.1]:
2023-01-06T01:09:20.986716+00:00 app[web.1]: > amazona-2#1.0.0 start
2023-01-06T01:09:20.986716+00:00 app[web.1]: > node backend/server.js
2023-01-06T01:09:20.986717+00:00 app[web.1]:
2023-01-06T01:09:21.087388+00:00 app[web.1]: node:internal/errors:484
2023-01-06T01:09:21.087389+00:00 app[web.1]: ErrorCaptureStackTrace(err);
2023-01-06T01:09:21.087390+00:00 app[web.1]: ^
2023-01-06T01:09:21.087390+00:00 app[web.1]:
2023-01-06T01:09:21.087391+00:00 app[web.1]: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/backend/controllers/productController.js' imported from /app/backend/routes/productRoutes.js
2023-01-06T01:09:21.087391+00:00 app[web.1]: at new NodeError (node:internal/errors:393:5)
2023-01-06T01:09:21.087392+00:00 app[web.1]: at finalizeResolution (node:internal/modules/esm/resolve:323:11)
2023-01-06T01:09:21.087392+00:00 app[web.1]: at moduleResolve (node:internal/modules/esm/resolve:916:10)
2023-01-06T01:09:21.087392+00:00 app[web.1]: at defaultResolve (node:internal/modules/esm/resolve:1124:11)
2023-01-06T01:09:21.087393+00:00 app[web.1]: at nextResolve (node:internal/modules/esm/loader:163:28)
2023-01-06T01:09:21.087393+00:00 app[web.1]: at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
2023-01-06T01:09:21.087393+00:00 app[web.1]: at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
2023-01-06T01:09:21.087394+00:00 app[web.1]: at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
2023-01-06T01:09:21.087395+00:00 app[web.1]: at link (node:internal/modules/esm/module_job:75:36) {
2023-01-06T01:09:21.087396+00:00 app[web.1]: code: 'ERR_MODULE_NOT_FOUND'
2023-01-06T01:09:21.087396+00:00 app[web.1]: }
2023-01-06T01:09:21.087426+00:00 app[web.1]:
2023-01-06T01:09:21.087427+00:00 app[web.1]: Node.js v18.12.1
2023-01-06T01:09:21.248317+00:00 heroku[web.1]: Process exited with status 1
2023-01-06T01:09:21.315476+00:00 heroku[web.1]: State changed from starting to crashed
2023-01-06T01:09:23.209214+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mern-amazona2-judo2000.herokuapp.com request_id=dd865b46-6a9f-478d-87ea-bfef1a20773d fwd="136.144.43.249" dyno= connect= service= status=503 bytes= protocol=https
2023-01-06T01:09:23.521669+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mern-amazona2-judo2000.herokuapp.com request_id=2c983834-c3e2-4a60-b39a-f55ecf4fa2fd fwd="172.98.33.99" dyno= connect= service=
status=503 bytes= protocol=https
2023-01-06T01:11:30.804412+00:00 heroku[web.1]: State changed from crashed to starting
2023-01-06T01:11:39.211361+00:00 heroku[web.1]: Starting process with command `npm start`
2023-01-06T01:11:41.347517+00:00 app[web.1]:
2023-01-06T01:11:41.347544+00:00 app[web.1]: > amazona-2#1.0.0 start
2023-01-06T01:11:41.347544+00:00 app[web.1]: > node backend/server.js
2023-01-06T01:11:41.347545+00:00 app[web.1]:
2023-01-06T01:11:41.460279+00:00 app[web.1]: node:internal/errors:484
2023-01-06T01:11:41.460280+00:00 app[web.1]: ErrorCaptureStackTrace(err);
2023-01-06T01:11:41.460281+00:00 app[web.1]: ^
2023-01-06T01:11:41.460281+00:00 app[web.1]:
2023-01-06T01:11:41.460281+00:00 app[web.1]: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/backend/controllers/productController.js' imported from /app/backend/routes/productRoutes.js
2023-01-06T01:11:41.460282+00:00 app[web.1]: at new NodeError (node:internal/errors:393:5)
2023-01-06T01:11:41.460282+00:00 app[web.1]: at finalizeResolution (node:internal/modules/esm/resolve:323:11)
2023-01-06T01:11:41.460283+00:00 app[web.1]: at moduleResolve (node:internal/modules/esm/resolve:916:10)
2023-01-06T01:11:41.460283+00:00 app[web.1]: at defaultResolve (node:internal/modules/esm/resolve:1124:11)
2023-01-06T01:11:41.460283+00:00 app[web.1]: at nextResolve (node:internal/modules/esm/loader:163:28)
2023-01-06T01:11:41.460285+00:00 app[web.1]: at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
2023-01-06T01:11:41.460285+00:00 app[web.1]: at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
2023-01-06T01:11:41.460285+00:00 app[web.1]: at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
2023-01-06T01:11:41.460285+00:00 app[web.1]: at link (node:internal/modules/esm/module_job:75:36) {
2023-01-06T01:11:41.460286+00:00 app[web.1]: code: 'ERR_MODULE_NOT_FOUND'
2023-01-06T01:11:41.460286+00:00 app[web.1]: }
2023-01-06T01:11:41.460297+00:00 app[web.1]:
2023-01-06T01:11:41.460298+00:00 app[web.1]: Node.js v18.12.1
2023-01-06T01:11:41.609123+00:00 heroku[web.1]: Process exited with status 1
2023-01-06T01:11:41.742528+00:00 heroku[web.1]: State changed from starting to crashed
2023-01-06T01:11:42.461013+00:00 heroku[web.1]: State changed from crashed to starting
2023-01-06T01:11:52.618745+00:00 heroku[web.1]: Starting process with command `npm start`
2023-01-06T01:11:54.470268+00:00 app[web.1]:
2023-01-06T01:11:54.470310+00:00 app[web.1]: > amazona-2#1.0.0 start
2023-01-06T01:11:54.470311+00:00 app[web.1]: > node backend/server.js
2023-01-06T01:11:54.470311+00:00 app[web.1]:
2023-01-06T01:11:54.565973+00:00 app[web.1]: node:internal/errors:484
2023-01-06T01:11:54.565975+00:00 app[web.1]: ErrorCaptureStackTrace(err);
2023-01-06T01:11:54.565975+00:00 app[web.1]: ^
2023-01-06T01:11:54.565976+00:00 app[web.1]:
2023-01-06T01:11:54.565977+00:00 app[web.1]: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/backend/controllers/productController.js' imported from /app/backend/routes/productRoutes.js
2023-01-06T01:11:54.565986+00:00 app[web.1]: at new NodeError (node:internal/errors:393:5)
2023-01-06T01:11:54.565986+00:00 app[web.1]: at finalizeResolution (node:internal/modules/esm/resolve:323:11)
2023-01-06T01:11:54.565986+00:00 app[web.1]: at moduleResolve (node:internal/modules/esm/resolve:916:10)
2023-01-06T01:11:54.565987+00:00 app[web.1]: at defaultResolve (node:internal/modules/esm/resolve:1124:11)
2023-01-06T01:11:54.565987+00:00 app[web.1]: at nextResolve (node:internal/modules/esm/loader:163:28)
2023-01-06T01:11:54.565987+00:00 app[web.1]: at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
2023-01-06T01:11:54.565987+00:00 app[web.1]: at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
2023-01-06T01:11:54.565993+00:00 app[web.1]: Node.js v18.12.12023-01-06T01:11:54.697714+00:00 heroku[web.1]: Process exited with status 1
2023-01-06T01:11:54.792281+00:00 heroku[web.1]: State changed from starting to crashed
2023-01-06T01:11:55.983110+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mern-amazona2-judo2000.herokuapp.com request_id=e373b75d-6a72-432d-9709-29e6c62063bd fwd="173.239.224.8" dyno= connect= service= status=503 bytes= protocol=https
2023-01-06T01:11:56.274300+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mern-amazona2-judo2000.herokuapp.com request_id=368733e0-a442-422d-97a1-1c3e0bc7681f fwd="173.239.224.10" dyno= connect= service= status=503 bytes= protocol=https
2023-01-06T01:11:30.571160+00:00 app[api]: Release v21 created by user judo2000#comcast.net
2023-01-06T01:11:30.571160+00:00 app[api]: Remove MONGO_URI config vars by user judo2000#comcast.net
2023-01-06T01:11:42.194061+00:00 app[api]: Set MONGODB_URI config vars by user judo2000#comcast.net
2023-01-06T01:11:42.194061+00:00 app[api]: Release v22 created by user judo2000#comcast.net
Here is the server.js
import express from 'express';
import path from 'path';
import dotenv from 'dotenv';
import connectDB from './config/connection.js';
import seedRoutes from './routes/seedRoutes.js';
import productRoutes from './routes/productRoutes.js';
import userRoutes from './routes/userRoutes.js';
import orderRoutes from './routes/orderRoutes.js';
dotenv.config();
connectDB();
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get('/api/keys/paypal', (req, res) => {
res.send(process.env.PAYPAL_CLIENT_ID || 'sb');
});
app.use('/api/seed', seedRoutes);
app.use('/api/products', productRoutes);
app.use('/api/users', userRoutes);
app.use('/api/orders', orderRoutes);
const __dirname = path.resolve();
app.use(express.static(path.join(__dirname, '/frontend/build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '/frontend/build/index.html'));
});
app.use((err, req, res, next) => {
res.status(500).send({ message: err.message });
});
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
});
Here is the productRoutes.js
import express, { Router } from 'express';
const router = express.Router();
import {
getProducts,
getProductBySlug,
getProductById,
} from '../controllers/productController.js';
router.route('/').get(getProducts);
router.route('/slug/:slug').get(getProductBySlug);
router.route('/:id').get(getProductById);
export default router;
And here is the productController
import Product from '../models/ProductModel.js';
const getProducts = async (req, res) => {
const products = await Product.find({});
res.send(products);
};
const getProductBySlug = async (req, res) => {
const product = await Product.findOne({ slug: req.params.slug });
if (product) {
res.send(product);
} else {
res.status(404).send({ message: 'Product Not Found' });
}
};
const getProductById = async (req, res) => {
const product = await Product.findById(req.params.id);
if (product) {
res.send(product);
} else {
res.status(404).send({ message: 'Product not found.' });
}
};
export { getProducts, getProductBySlug, getProductById };
You have a path mis-match. Change controllers to controller or vise-versa (whichever is true).
The error is:
Cannot find module '/app/backend/controllers/productController.js'
and your path is:
/app/backend/controller/productController.js

Node.js heroku deploy failure

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.

Heroku Node.js Error "Error MongoNetworkError", "Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch"

I'm new in nodeJS,
I want upload my backend on Heroku to my Frontend but I got this Error
This code work in localhost,
I Added NODE_DATABASE in Heroku
"Error MongoNetworkError", "Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch"
my app.js
const dotenv = require("dotenv").load();
const express = require("express");
const session = require("express-session");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const passport = require("passport");
const morgan = require("morgan");
const cors = require("cors");
const LocalStrategy = require("passport-local").Strategy;
const routes = require("./routes");
const User = require("./models/User");
const MongoStore = require("connect-mongo")(session);
const PORT = process.env.PORT || 9000;
const app = express();
app.use(bodyParser.json());
app.use(morgan("combined"));
app.use(cors());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use(
session({
secret: "Norbert",
resave: false,
saveUninitialized: true,
cookie: { maxAge: 86400000 },
store: new MongoStore({
mongooseConnection: mongoose.connection,
}),
})
);
app.use(express.urlencoded({ extended: true }));
app.use(passport.initialize());
app.use(passport.session());
mongoose.connect(process.env.NODE_DATABASE, { useNewUrlParser: true });
const conn = mongoose.connection;
conn.on("error", console.error.bind(console, "connection error:"));
conn.once("open", () => {
console.log("Connected to mlab database!");
app.listen(PORT, () => console.log(`App is listening on port ${PORT}!`));
app.use("/api", routes);
});
heroku logs
2020-08-20T10:05:53.139695+00:00 app[web.1]: [nodemon] starting `babel-node src/app.js`
2020-08-20T10:05:54.067319+00:00 app[web.1]: Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
2020-08-20T10:05:55.810360+00:00 app[web.1]: connection error: MongoNetworkError: connection 5 to cluster0-shard-00-01.ho4na.mongodb.net:27017 closed
2020-08-20T10:05:55.810364+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:276:9)
2020-08-20T10:05:55.810364+00:00 app[web.1]: at Object.onceWrapper (events.js:422:26)
2020-08-20T10:05:55.810365+00:00 app[web.1]: at TLSSocket.emit (events.js:327:22)
2020-08-20T10:05:55.810365+00:00 app[web.1]: at net.js:674:12
2020-08-20T10:05:55.810365+00:00 app[web.1]: at TCP.done (_tls_wrap.js:563:7) {
2020-08-20T10:05:55.810369+00:00 app[web.1]: name: 'MongoNetworkError',
2020-08-20T10:05:55.810369+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2020-08-20T10:05:55.810369+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-08-20T10:05:55.810370+00:00 app[web.1]: }
2020-08-20T10:05:55.828088+00:00 app[web.1]: [nodemon] clean exit - waiting for changes before restart
2020-08-20T10:06:50.472320+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-20T10:06:50.496970+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-20T10:06:50.575809+00:00 heroku[web.1]: Process exited with status 137
2020-08-20T10:06:50.607171+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-20T10:06:50.609395+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-20T10:06:55.049996+00:00 heroku[web.1]: Starting process with command `npm start`
2020-08-20T10:06:57.284172+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2020-08-20T10:06:57.284202+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2020-08-20T10:06:57.687757+00:00 app[web.1]:
2020-08-20T10:06:57.687800+00:00 app[web.1]: > notes#1.0.0 start /app
2020-08-20T10:06:57.687801+00:00 app[web.1]: > nodemon --exec babel-node src/app.js
2020-08-20T10:06:57.687802+00:00 app[web.1]:
2020-08-20T10:06:58.012979+00:00 app[web.1]: [nodemon] 1.18.10
2020-08-20T10:06:58.014501+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2020-08-20T10:06:58.015004+00:00 app[web.1]: [nodemon] watching: *.*
2020-08-20T10:06:58.015615+00:00 app[web.1]: [nodemon] starting `babel-node src/app.js`
2020-08-20T10:06:59.007296+00:00 app[web.1]: Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
2020-08-20T10:07:01.309982+00:00 app[web.1]: connection error: MongoNetworkError: connection 5 to cluster0-shard-00-00.ho4na.mongodb.net:27017 closed
2020-08-20T10:07:01.309998+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:276:9)
2020-08-20T10:07:01.310000+00:00 app[web.1]: at Object.onceWrapper (events.js:422:26)
2020-08-20T10:07:01.310000+00:00 app[web.1]: at TLSSocket.emit (events.js:327:22)
2020-08-20T10:07:01.310001+00:00 app[web.1]: at net.js:674:12
2020-08-20T10:07:01.310001+00:00 app[web.1]: at TCP.done (_tls_wrap.js:563:7) {
2020-08-20T10:07:01.310002+00:00 app[web.1]: name: 'MongoNetworkError',
2020-08-20T10:07:01.310002+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2020-08-20T10:07:01.310003+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-08-20T10:07:01.310003+00:00 app[web.1]: }
2020-08-20T10:07:01.340827+00:00 app[web.1]: [nodemon] clean exit - waiting for changes before restart
2020-08-20T10:07:55.450102+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-20T10:07:55.473020+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-20T10:07:55.500784+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2020-08-20T10:07:55.575750+00:00 heroku[web.1]: Process exited with status 22
2020-08-20T10:07:55.620964+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-20T10:10:09.137371+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=favnoteback.herokuapp.com request_id=111d6959-56ad-4449-9ba6-77fa7a426577 fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
2020-08-20T10:10:10.310013+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=favnoteback.herokuapp.com request_id=dba1ddd0-36d1-44f7-886b-1e22f8ca526d fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
2020-08-20T10:11:20.182121+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=favnoteback.herokuapp.com request_id=fc425fd1-dcce-49e3-b9af-eae31c9d35f5 fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
2020-08-20T10:11:20.884144+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=favnoteback.herokuapp.com request_id=e81ab2e2-c476-494f-a2f3-2c5a3281fc55 fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
2020-08-20T10:19:21.000000+00:00 app[api]: Build started by user myemail#gmail.com
2020-08-20T10:19:47.820767+00:00 app[api]: Deploy f6a0950d by user myemail#gmail.com
2020-08-20T10:19:47.820767+00:00 app[api]: Release v14 created by user myemail#gmail.com
2020-08-20T10:19:48.014495+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-20T10:19:49.000000+00:00 app[api]: Build succeeded
2020-08-20T10:19:52.366993+00:00 heroku[web.1]: Starting process with command `npm start`
2020-08-20T10:19:55.049310+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2020-08-20T10:19:55.049332+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2020-08-20T10:19:55.560928+00:00 app[web.1]:
2020-08-20T10:19:55.560950+00:00 app[web.1]: > notes#1.0.0 start /app
2020-08-20T10:19:55.560951+00:00 app[web.1]: > nodemon --exec babel-node src/app.js
2020-08-20T10:19:55.560951+00:00 app[web.1]:
2020-08-20T10:19:55.989648+00:00 app[web.1]: [nodemon] 1.18.10
2020-08-20T10:19:55.990902+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2020-08-20T10:19:55.991361+00:00 app[web.1]: [nodemon] watching: *.*
2020-08-20T10:19:55.991938+00:00 app[web.1]: [nodemon] starting `babel-node src/app.js`
2020-08-20T10:19:57.234412+00:00 app[web.1]: Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
2020-08-20T10:19:58.962557+00:00 app[web.1]: the options [useUnifiedTopology] is not supported
2020-08-20T10:19:59.745897+00:00 app[web.1]: /app/node_modules/mongodb/lib/operations/mongo_client_ops.js:474
2020-08-20T10:19:59.745912+00:00 app[web.1]: throw err;
2020-08-20T10:19:59.745913+00:00 app[web.1]: ^
2020-08-20T10:19:59.745913+00:00 app[web.1]:
2020-08-20T10:19:59.745914+00:00 app[web.1]: MongoNetworkError: connection 9 to cluster0-shard-00-00.ho4na.mongodb.net:27017 closed
2020-08-20T10:19:59.745915+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:276:9)
2020-08-20T10:19:59.745916+00:00 app[web.1]: at Object.onceWrapper (events.js:422:26)
2020-08-20T10:19:59.745917+00:00 app[web.1]: at TLSSocket.emit (events.js:327:22)
2020-08-20T10:19:59.745917+00:00 app[web.1]: at net.js:674:12
2020-08-20T10:19:59.745917+00:00 app[web.1]: at TCP.done (_tls_wrap.js:563:7) {
2020-08-20T10:19:59.745918+00:00 app[web.1]: name: 'MongoNetworkError',
2020-08-20T10:19:59.745918+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2020-08-20T10:19:59.745919+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-08-20T10:19:59.745919+00:00 app[web.1]: }
2020-08-20T10:19:59.763100+00:00 app[web.1]: [nodemon] app crashed - waiting for file changes before starting...
2020-08-20T10:20:52.546213+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-20T10:20:52.568907+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-20T10:20:52.691301+00:00 heroku[web.1]: Process exited with status 137
2020-08-20T10:20:52.742514+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-20T10:20:52.744625+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-20T10:20:56.145248+00:00 heroku[web.1]: Starting process with command `npm start`
2020-08-20T10:20:58.152568+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2020-08-20T10:20:58.152590+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2020-08-20T10:20:58.572627+00:00 app[web.1]:
2020-08-20T10:20:58.572655+00:00 app[web.1]: > notes#1.0.0 start /app
2020-08-20T10:20:58.572656+00:00 app[web.1]: > nodemon --exec babel-node src/app.js
2020-08-20T10:20:58.572656+00:00 app[web.1]:
2020-08-20T10:20:58.948432+00:00 app[web.1]: [nodemon] 1.18.10
2020-08-20T10:20:58.949669+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2020-08-20T10:20:58.950054+00:00 app[web.1]: [nodemon] watching: *.*
2020-08-20T10:20:58.950608+00:00 app[web.1]: [nodemon] starting `babel-node src/app.js`
2020-08-20T10:20:59.976088+00:00 app[web.1]: Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
2020-08-20T10:21:01.137742+00:00 app[web.1]: the options [useUnifiedTopology] is not supported
2020-08-20T10:21:01.921790+00:00 app[web.1]: connection error: MongoNetworkError: connection 8 to cluster0-shard-00-02.ho4na.mongodb.net:27017 closed
2020-08-20T10:21:01.921802+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:276:9)
2020-08-20T10:21:01.921803+00:00 app[web.1]: at Object.onceWrapper (events.js:422:26)
2020-08-20T10:21:01.921804+00:00 app[web.1]: at TLSSocket.emit (events.js:327:22)
2020-08-20T10:21:01.921804+00:00 app[web.1]: at net.js:674:12
2020-08-20T10:21:01.921805+00:00 app[web.1]: at TCP.done (_tls_wrap.js:563:7) {
2020-08-20T10:21:01.921805+00:00 app[web.1]: name: 'MongoNetworkError',
2020-08-20T10:21:01.921806+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2020-08-20T10:21:01.921806+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-08-20T10:21:01.921807+00:00 app[web.1]: }
2020-08-20T10:21:01.933176+00:00 app[web.1]: /app/node_modules/mongodb/lib/operations/mongo_client_ops.js:474
2020-08-20T10:21:01.933178+00:00 app[web.1]: throw err;
2020-08-20T10:21:01.933178+00:00 app[web.1]: ^
2020-08-20T10:21:01.933179+00:00 app[web.1]:
2020-08-20T10:21:01.933180+00:00 app[web.1]: MongoNetworkError: connection 11 to cluster0-shard-00-02.ho4na.mongodb.net:27017 closed
2020-08-20T10:21:01.933180+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:276:9)
2020-08-20T10:21:01.933181+00:00 app[web.1]: at Object.onceWrapper (events.js:422:26)
2020-08-20T10:21:01.933181+00:00 app[web.1]: at TLSSocket.emit (events.js:327:22)
2020-08-20T10:21:01.933182+00:00 app[web.1]: at net.js:674:12
2020-08-20T10:21:01.933182+00:00 app[web.1]: at TCP.done (_tls_wrap.js:563:7) {
2020-08-20T10:21:01.933182+00:00 app[web.1]: name: 'MongoNetworkError',
2020-08-20T10:21:01.933183+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2020-08-20T10:21:01.933183+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-08-20T10:21:01.933183+00:00 app[web.1]: }
2020-08-20T10:21:01.960242+00:00 app[web.1]: [nodemon] app crashed - waiting for file changes before starting...
2020-08-20T10:21:47.512311+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=favnoteback.herokuapp.com request_id=a0b75780-abfa-4727-99b4-cdf9bc42bb62 fwd="85.221.154.50" dyno= connect= service= status=503 bytes=
protocol=https
2020-08-20T10:21:56.438920+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-20T10:21:56.456159+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-20T10:21:56.480098+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2020-08-20T10:21:56.526046+00:00 heroku[web.1]: Process exited with status 22
2020-08-20T10:21:56.561169+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-20T10:21:57.783155+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=favnoteback.herokuapp.com request_id=aa62afa9-ae33-40b3-9b54-d25bed03c5fa fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
2020-08-20T10:21:58.572293+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=favnoteback.herokuapp.com request_id=afed98ae-b48b-4d0f-944e-551cdc703571 fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
I'm very appreciated if whose help me in this Error
OK I found resolve
application could not connect with mongodb,
resolve is add 0.0.0.0/0 ip on white list in mongodb

Error while deploying app on Heroku MongoDB connection

I created the app using express and MongoDB. When I run the app locally it runs perfectly.I created a PostDB database on MongoDB atlas and generated and got connection string.I want to deploy this app using heroku but I don't why it gives this error.Please help me. Thanks in advance.
This is my connection string:
mongoose.connect("\mongodb+srv://Admin:minnu#mongodb01.irdlb.mongodb.net/PostDB",{useNewUrlParser:true,useCreateIndex:true, useUnifiedTopology: true},function(err,db){
if (err) {
console.log('Unable to connect to the server. Please start the server. Error:', err);
} else {
console.log('Connected to Server successfully!');
}});
This is the error I get:
2020-07-22T13:10:59.614060+00:00 app[web.1]: commonWireVersion: null
2020-07-22T13:10:59.614061+00:00 app[web.1]: }
2020-07-22T13:10:59.614061+00:00 app[web.1]: }
2020-07-22T13:10:59.631071+00:00 app[web.1]: Unable to connect to the server. Please start the server. Error: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
2020-07-22T13:10:59.631074+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:828:32)
2020-07-22T13:10:59.631075+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:335:15)
2020-07-22T13:10:59.631076+00:00 app[web.1]: at Object.<anonymous> (/app/Models/User.js:2:10)
2020-07-22T13:10:59.631076+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)
2020-07-22T13:10:59.631077+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-07-22T13:10:59.631077+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)
2020-07-22T13:10:59.631078+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-07-22T13:10:59.631078+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1026:19)
2020-07-22T13:10:59.631079+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:72:18)
2020-07-22T13:10:59.631079+00:00 app[web.1]: at Object.<anonymous> (/app/Routes/Posts.js:6:12)
2020-07-22T13:10:59.631079+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)
2020-07-22T13:10:59.631080+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-07-22T13:10:59.631080+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)
2020-07-22T13:10:59.631081+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-07-22T13:10:59.631081+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1026:19)
2020-07-22T13:10:59.631081+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:72:18) {
2020-07-22T13:10:59.631082+00:00 app[web.1]: reason: TopologyDescription {
2020-07-22T13:10:59.631082+00:00 app[web.1]: type: 'Single',
2020-07-22T13:10:59.631083+00:00 app[web.1]: setName: null,
2020-07-22T13:10:59.631083+00:00 app[web.1]: maxSetVersion: null,
2020-07-22T13:10:59.631083+00:00 app[web.1]: maxElectionId: null,
2020-07-22T13:10:59.631084+00:00 app[web.1]: servers: Map { 'localhost:27017' => [ServerDescription] },
2020-07-22T13:10:59.631084+00:00 app[web.1]: stale: false,
2020-07-22T13:10:59.631085+00:00 app[web.1]: compatible: true,
2020-07-22T13:10:59.631085+00:00 app[web.1]: compatibilityError: null,
2020-07-22T13:10:59.631086+00:00 app[web.1]: logicalSessionTimeoutMinutes: null,
2020-07-22T13:10:59.631086+00:00 app[web.1]: heartbeatFrequencyMS: 10000,
2020-07-22T13:10:59.631086+00:00 app[web.1]: localThresholdMS: 15,
2020-07-22T13:10:59.631087+00:00 app[web.1]: commonWireVersion: null
2020-07-22T13:10:59.631087+00:00 app[web.1]: }
2020-07-22T13:10:59.631087+00:00 app[web.1]: }
2020-07-22T13:11:29.817201+00:00 heroku[web.1]: State changed from starting to up
2020-07-22T13:43:44.978055+00:00 heroku[web.1]: Idling
2020-07-22T13:43:44.980176+00:00 heroku[web.1]: State changed from up to down
2020-07-22T13:43:46.293776+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-07-22T13:43:46.385591+00:00 heroku[web.1]: Process exited with status 143
2020-07-22T15:23:20.000000+00:00 app[api]: Build started by user mamadgiaishwarya#gmail.com
2020-07-22T15:23:41.274124+00:00 app[api]: Deploy 9e2202b9 by user mamadgiaishwarya#gmail.com
2020-07-22T15:23:41.274124+00:00 app[api]: Release v9 created by user mamadgiaishwarya#gmail.com
2020-07-22T15:23:41.454375+00:00 heroku[web.1]: State changed from down to starting
2020-07-22T15:23:42.000000+00:00 app[api]: Build succeeded
2020-07-22T15:23:43.755247+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-22T15:23:46.020199+00:00 app[web.1]:
2020-07-22T15:23:46.020218+00:00 app[web.1]: > ejs-challenge#1.0.0 start /app
2020-07-22T15:23:46.020219+00:00 app[web.1]: > node app.js
2020-07-22T15:23:46.020219+00:00 app[web.1]:
2020-07-22T15:23:46.753513+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2020-07-22T15:23:46.753525+00:00 app[web.1]: designed for a production environment, as it will leak
2020-07-22T15:23:46.753554+00:00 app[web.1]: memory, and will not scale past a single process.
2020-07-22T15:23:46.770376+00:00 app[web.1]: Server started on port 3000
2020-07-22T15:23:47.305407+00:00 heroku[web.1]: State changed from starting to up
2020-07-22T15:23:48.056394+00:00 app[web.1]: Connected to Server successfully!
2020-07-22T15:23:48.059001+00:00 app[web.1]: Connected to Server successfully!
2020-07-22T15:24:25.538134+00:00 heroku[router]: at=info method=GET path="/" host=shielded-citadel-75286.herokuapp.com request_id=a2276768-c8b4-4937-a8f9-feb2e1cc9d00 fwd="106.200.146.62" dyno=web.1 connect=0ms service=1360ms status=200 bytes=4199 protocol=https
2020-07-22T15:24:26.201469+00:00 heroku[router]: at=info method=GET path="/css/styles.css" host=shielded-citadel-75286.herokuapp.com request_id=1d330f4c-66fd-407c-a8ed-57ba80507318 fwd="106.200.146.62" dyno=web.1 connect=1ms service=9ms status=200 bytes=2179 protocol=https
2020-07-22T15:24:26.284481+00:00 heroku[router]: at=info method=GET path="/images/logo.jpg" host=shielded-citadel-75286.herokuapp.com request_id=96a94f69-2984-4b7f-8e5e-1ae6f12493e6 fwd="106.200.146.62" dyno=web.1 connect=0ms service=11ms status=200 bytes=8897 protocol=https
2020-07-22T15:24:26.318935+00:00 heroku[router]: at=info method=GET path="/images/butterfly.gif" host=shielded-citadel-75286.herokuapp.com request_id=f54f11ef-31a4-4fdf-ad7f-c5d47c354afb fwd="106.200.146.62" dyno=web.1 connect=0ms service=45ms status=200 bytes=687572 protocol=https
2020-07-22T15:24:51.370552+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=shielded-citadel-75286.herokuapp.com request_id=396f3ab9-b44b-4432-888e-792eb45268e2 fwd="106.200.146.62" dyno=web.1 connect=0ms service=5ms status=404 bytes=394 protocol=https
2020-07-22T15:26:13.000000+00:00 app[api]: Build started by user mamadgiaishwarya#gmail.com
2020-07-22T15:26:35.089490+00:00 app[api]: Release v10 created by user mamadgiaishwarya#gmail.com
2020-07-22T15:26:35.089490+00:00 app[api]: Deploy 7fd231d2 by user mamadgiaishwarya#gmail.com
2020-07-22T15:26:36.000000+00:00 app[api]: Build succeeded
2020-07-22T15:26:36.726907+00:00 heroku[web.1]: Restarting
2020-07-22T15:26:36.741521+00:00 heroku[web.1]: State changed from up to starting
2020-07-22T15:26:37.654962+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-07-22T15:26:37.782161+00:00 heroku[web.1]: Process exited with status 143
2020-07-22T15:26:39.941929+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-22T15:26:42.451886+00:00 app[web.1]:
2020-07-22T15:26:42.451908+00:00 app[web.1]: > ejs-challenge#1.0.0 start /app
2020-07-22T15:26:42.451908+00:00 app[web.1]: > node app.js
2020-07-22T15:26:42.451909+00:00 app[web.1]:
2020-07-22T15:26:43.528332+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2020-07-22T15:26:43.528343+00:00 app[web.1]: designed for a production environment, as it will leak
2020-07-22T15:26:43.528344+00:00 app[web.1]: memory, and will not scale past a single process.
2020-07-22T15:26:43.537025+00:00 app[web.1]: Server started on port 3000
2020-07-22T15:26:43.977021+00:00 heroku[web.1]: State changed from starting to up
2020-07-22T15:26:44.829130+00:00 app[web.1]: Connected to Server successfully!
2020-07-22T15:26:44.831445+00:00 app[web.1]: Connected to Server successfully!
2020-07-22T15:28:23.000000+00:00 app[api]: Build started by user mamadgiaishwarya#gmail.com
2020-07-22T15:28:45.263212+00:00 app[api]: Deploy c7cbd9d0 by user mamadgiaishwarya#gmail.com
2020-07-22T15:28:45.263212+00:00 app[api]: Release v11 created by user mamadgiaishwarya#gmail.com
2020-07-22T15:28:45.446526+00:00 heroku[web.1]: Restarting
2020-07-22T15:28:45.448387+00:00 heroku[web.1]: State changed from up to starting
2020-07-22T15:28:46.000000+00:00 app[api]: Build succeeded
2020-07-22T15:28:46.651703+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-07-22T15:28:46.746865+00:00 heroku[web.1]: Process exited with status 143
2020-07-22T15:28:49.098450+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-22T15:28:51.924571+00:00 app[web.1]:
2020-07-22T15:28:51.924589+00:00 app[web.1]: > ejs-challenge#1.0.0 start /app
2020-07-22T15:28:51.924589+00:00 app[web.1]: > node app.js
2020-07-22T15:28:51.924589+00:00 app[web.1]:
2020-07-22T15:28:52.898117+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2020-07-22T15:28:52.898161+00:00 app[web.1]: designed for a production environment, as it will leak
2020-07-22T15:28:52.898162+00:00 app[web.1]: memory, and will not scale past a single process.
2020-07-22T15:28:52.905188+00:00 app[web.1]: Server started on port 3000
2020-07-22T15:28:53.428020+00:00 heroku[web.1]: State changed from starting to up
I think you have a mistake in your connection string.
According to MongoDB docs, connection string should start with mongodb://, not with the leading \ in the front.
I also recommend you to use Promises or Async/Await for your connections, like the following snippet below:
// Start connection via Mongoose.
mongoose
.connect(YOUR_CONNECTION_STRING, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
})
.then(() => {
console.log('Database connected successfully!');
})
.catch((err) => {
console.log('Error connecting with error code:', err);
});
app.listen(PORT, () => {
console.log('Server starts at port...');
}
It makes code much easier to read.
Alternatively, do you have any exceptions that you do not catch before connecting to the database? It might bubble up and crash your database connection for security reasons.

Heroku Error, I didn't understand that is this error related to npm packages or with timeout

I am trying to deploy my express app on Heroku, but it is crashing every time with following logs: -
2019-03-22T19:26:26.149208+00:00 heroku[web.1]: State changed from starting to crashed
2019-03-22T19:26:26.122569+00:00 heroku[web.1]: Process exited with status 1
2019-03-22T19:26:25.977206+00:00 app[web.1]:
2019-03-22T19:26:25.977226+00:00 app[web.1]: > Server#1.0.0 start /app
2019-03-22T19:26:25.977228+00:00 app[web.1]: > node server.js
2019-03-22T19:26:25.977229+00:00 app[web.1]:
2019-03-22T19:26:26.059671+00:00 app[web.1]: internal/modules/cjs/loader.js:584
2019-03-22T19:26:26.059674+00:00 app[web.1]: throw err;
2019-03-22T19:26:26.059676+00:00 app[web.1]: ^
2019-03-22T19:26:26.059678+00:00 app[web.1]:
2019-03-22T19:26:26.059680+00:00 app[web.1]: Error: Cannot find module '/app/server.js'
2019-03-22T19:26:26.059682+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
2019-03-22T19:26:26.059683+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:508:25)
2019-03-22T19:26:26.059685+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
2019-03-22T19:26:26.059687+00:00 app[web.1]: at startup (internal/bootstrap/node.js:283:19)
2019-03-22T19:26:26.059689+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
2019-03-22T19:26:26.065404+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-03-22T19:26:26.065766+00:00 app[web.1]: npm ERR! errno 1
2019-03-22T19:26:26.066805+00:00 app[web.1]: npm ERR! Server#1.0.0 start: `node server.js`
2019-03-22T19:26:26.066916+00:00 app[web.1]: npm ERR! Exit status 1
2019-03-22T19:26:26.067117+00:00 app[web.1]: npm ERR!
2019-03-22T19:26:26.067233+00:00 app[web.1]: npm ERR! Failed at the Server#1.0.0 start script.
2019-03-22T19:26:26.067395+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-03-22T19:26:26.071997+00:00 app[web.1]:
2019-03-22T19:26:26.072138+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-03-22T19:26:26.072224+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-03-22T19_26_26_068Z-debug.log
2019-03-22T19:27:18.000000+00:00 app[api]: Build started by user ab98647#gmail.com
2019-03-22T19:27:32.768091+00:00 heroku[web.1]: State changed from crashed to starting
2019-03-22T19:27:34.827273+00:00 heroku[web.1]: Starting process with command `npm start`
2019-03-22T19:27:32.578293+00:00 app[api]: Release v13 created by user ab98647#gmail.com
2019-03-22T19:27:32.578293+00:00 app[api]: Deploy 7e0d91c1 by user ab98647#gmail.com
2019-03-22T19:27:33.000000+00:00 app[api]: Build succeeded
2019-03-22T19:27:36.739160+00:00 app[web.1]:
2019-03-22T19:27:36.739182+00:00 app[web.1]: > Server#1.0.0 start /app
2019-03-22T19:27:36.739184+00:00 app[web.1]: > node server.js
2019-03-22T19:27:36.739185+00:00 app[web.1]:
2019-03-22T19:27:37.087619+00:00 app[web.1]: App is working
2019-03-22T19:27:37.617321+00:00 heroku[web.1]: State changed from starting to up
2019-03-22T19:30:44.261549+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=secret-beach-23042.herokuapp.com request_id=3a765852-d9f6-492b-869e-8e6f6f57cdf7 fwd="47.247.184.33" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
2019-03-22T19:31:23.585873+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=secret-beach-23042.herokuapp.com request_id=3c116fc4-4d3f-4b55-ad9f-97942e9e9e99 fwd="47.247.184.33" dyno=web.1 connect=1ms service=30003ms status=503 bytes=0 protocol=https
2019-03-22T19:38:19.581701+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=secret-beach-23042.herokuapp.com request_id=3a9756f6-0c75-419e-9724-b76da81b853b fwd="47.247.184.33" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
2019-03-22T20:01:13.086387+00:00 heroku[web.1]: Idling
2019-03-22T20:01:13.091324+00:00 heroku[web.1]: State changed from up to down
2019-03-22T20:01:14.577272+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-03-22T20:01:14.691025+00:00 heroku[web.1]: Process exited with status 143
2019-03-22T20:41:21.048924+00:00 heroku[web.1]: State changed from down to starting
2019-03-22T20:41:23.311286+00:00 heroku[web.1]: Starting process with command `npm start`
2019-03-22T20:41:25.122476+00:00 app[web.1]:
2019-03-22T20:41:25.122494+00:00 app[web.1]: > Server#1.0.0 start /app
2019-03-22T20:41:25.122496+00:00 app[web.1]: > node server.js
2019-03-22T20:41:25.122498+00:00 app[web.1]:
2019-03-22T20:41:25.655023+00:00 heroku[web.1]: State changed from starting to up
2019-03-22T20:41:25.452310+00:00 app[web.1]: App is working
2019-03-22T20:46:58.094883+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=secret-beach-23042.herokuapp.com request_id=592a14a7-b683-4f5a-9593-ed0eca3d1c7e fwd="47.247.184.33" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
2019-03-22T20:50:12.000000+00:00 app[api]: Build started by user ab98647#gmail.com
2019-03-22T20:50:27.551012+00:00 app[api]: Deploy 58e9e00f by user ab98647#gmail.com
2019-03-22T20:50:27.551012+00:00 app[api]: Release v14 created by user ab98647#gmail.com
2019-03-22T20:50:28.000000+00:00 app[api]: Build succeeded
2019-03-22T20:50:31.597374+00:00 heroku[web.1]: Restarting
2019-03-22T20:50:31.619924+00:00 heroku[web.1]: State changed from up to starting
2019-03-22T20:50:32.995500+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-03-22T20:50:32.995500+00:00 heroku[web.1]: Process exited with status 143
2019-03-22T20:50:34.030210+00:00 heroku[web.1]: Starting process with command `npm start`
2019-03-22T20:50:37.589947+00:00 app[web.1]:
2019-03-22T20:50:37.589988+00:00 app[web.1]: > Server#1.0.0 start /app
2019-03-22T20:50:37.589990+00:00 app[web.1]: > node server.js
2019-03-22T20:50:37.589992+00:00 app[web.1]:
2019-03-22T20:50:38.620173+00:00 heroku[web.1]: State changed from starting to up
2019-03-22T20:50:38.544170+00:00 app[web.1]: App is working
2019-03-22T20:56:30.000000+00:00 app[api]: Build started by user ab98647#gmail.com
2019-03-22T20:56:45.960310+00:00 heroku[web.1]: Restarting
2019-03-22T20:56:45.978197+00:00 heroku[web.1]: State changed from up to starting
2019-03-22T20:56:45.647303+00:00 app[api]: Release v15 created by user ab98647#gmail.com
2019-03-22T20:56:45.647303+00:00 app[api]: Deploy f2758b5c by user ab98647#gmail.com
2019-03-22T20:56:46.000000+00:00 app[api]: Build succeeded
2019-03-22T20:56:47.541219+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-03-22T20:56:47.659446+00:00 heroku[web.1]: Process exited with status 143
2019-03-22T20:56:48.601100+00:00 heroku[web.1]: Starting process with command `npm start`
2019-03-22T20:56:50.396013+00:00 app[web.1]:
2019-03-22T20:56:50.396063+00:00 app[web.1]: > Server#1.0.0 start /app
2019-03-22T20:56:50.396065+00:00 app[web.1]: > node server.js
2019-03-22T20:56:50.396067+00:00 app[web.1]:
2019-03-22T20:56:50.845287+00:00 heroku[web.1]: State changed from starting to up
2019-03-22T20:56:50.782758+00:00 app[web.1]: App is working
2019-03-22T21:31:11.982402+00:00 heroku[web.1]: Idling
2019-03-22T21:31:11.992917+00:00 heroku[web.1]: State changed from up to down
2019-03-22T21:31:12.708220+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-03-22T21:31:12.769110+00:00 heroku[web.1]: Process exited with status 143
2019-03-23T06:27:23.000000+00:00 app[api]: Build started by user ab98647#gmail.com
2019-03-23T06:27:39.496098+00:00 app[api]: Release v16 created by user ab98647#gmail.com
2019-03-23T06:27:39.496098+00:00 app[api]: Deploy fbae53e0 by user ab98647#gmail.com
2019-03-23T06:27:40.388432+00:00 heroku[web.1]: State changed from down to starting
2019-03-23T06:27:43.640584+00:00 heroku[web.1]: Starting process with command `npm start`
2019-03-23T06:27:40.000000+00:00 app[api]: Build succeeded
2019-03-23T06:27:46.450974+00:00 app[web.1]:
2019-03-23T06:27:46.450990+00:00 app[web.1]: > Server#1.0.0 start /app
2019-03-23T06:27:46.450992+00:00 app[web.1]: > node server.js
2019-03-23T06:27:46.450994+00:00 app[web.1]:
2019-03-23T06:27:46.969621+00:00 app[web.1]: App is working
2019-03-23T06:27:47.560758+00:00 heroku[web.1]: State changed from starting to up
Here even after build succeeded app crashed, why is it so and I can't understand the error like is it related to npm or timeout or something else ?
The Procfile contains : web: node server.js
Here is my package.json file
{
"name": "Server",
"version": "1.0.0",
"main": "server.js",
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"express": "^4.16.4",
"knex": "^0.16.3",
"mysql": "^2.16.0"
},
"devDependencies": {
"nodemon": "^1.18.9"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/ankit986/Brainly-React-Project/tree/master/Backend/Backend/Server"
},
"description": ""
}
and the server.js file is:-
const express = require('express');
const bodyParser = require('body-parser');
const bcrypt = require('bcrypt-nodejs');
const cors = require('cors');
const knex = require('knex')
const mysql = knex({
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'root',
password : 'Amit',
database : 'brainly'
}
});
const app = express();
const Signin = require('./SigninServer.js');
const Register = require('./RegisterServer.js');
const Profile = require('./ProfileServer.js');
const Image = require('./ImageServer.js');
app.use(bodyParser.json());
app.use(cors());
app.get('/',(req, res) => {
res.send("working");
})
app.post('/signin', (req, res) => {Signin.handleSignin(req, res, mysql, bcrypt)})
app.post('/register', (req, res) => {Register.handleRegister(req, res, mysql, bcrypt)})
app.get('/profile/:id',(req, res) => {Profile.handleProfile(req, res, mysql, bcrypt)})
app.put('/image', (req, res) => {Image.handleImage(req, res, mysql, bcrypt)})
app.listen(process.env.PORT || 3000, ()=>{
console.log("App is working");
}) ;

Resources