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.
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 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
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.
Listen method
let port = process.env.PORT;
if (port == null || port == "")
{port = 3000; }
app.listen(port);
app.listen(port, function() {
console.log("Server has started successfully!");
});
Procfile
web: node app.js
Package.json
{
"name": "todolist-v1",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"engines": {
"node": "12.18.0"
},
"dependencies": {
"body-parser": "^1.18.3",
"ejs": "^2.6.1",
"express": "^4.16.3",
"lodash": "^4.17.19",
"mongoose": "^5.9.26"
}
}
After deploying the app on heroku
This is being displayed when I am visiting the specified address in my terminal
After logging the error in terminal
$ heroku logs --tail
2020-08-06T17:58:14.031722+00:00 app[api]: Initial release by user saadahmad728#gmail.com
2020-08-06T17:58:14.031722+00:00 app[api]: Release v1 created by user saadahmad728#gmail.com
2020-08-06T17:58:14.344269+00:00 app[api]: Enable Logplex by user saadahmad728#gmail.com
2020-08-06T17:58:14.344269+00:00 app[api]: Release v2 created by user saadahmad728#gmail.com
2020-08-06T18:27:53.000000+00:00 app[api]: Build started by user saadahmad728#gmail.com
2020-08-06T18:28:08.541198+00:00 app[api]: Deploy 08926525 by user saadahmad728#gmail.com
2020-08-06T18:28:08.541198+00:00 app[api]: Release v3 created by user saadahmad728#gmail.com
2020-08-06T18:28:08.555631+00:00 app[api]: Scaled to web#1:Free by user saadahmad728#gmail.com
2020-08-06T18:28:09.000000+00:00 app[api]: Build succeeded
2020-08-06T18:28:12.043887+00:00 heroku[web.1]: Starting process with command `node app.js`
2020-08-06T18:28:15.554606+00:00 app[web.1]: events.js:292
2020-08-06T18:28:15.554621+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-08-06T18:28:15.554622+00:00 app[web.1]: ^
2020-08-06T18:28:15.554622+00:00 app[web.1]:
2020-08-06T18:28:15.554622+00:00 app[web.1]: Error: listen EADDRINUSE: address already in use :::43074
2020-08-06T18:28:15.554623+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1313:16)
2020-08-06T18:28:15.554623+00:00 app[web.1]: at listenInCluster (net.js:1361:12)
2020-08-06T18:28:15.554624+00:00 app[web.1]: at Server.listen (net.js:1447:7)
2020-08-06T18:28:15.554624+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2020-08-06T18:28:15.554625+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:146:5)
2020-08-06T18:28:15.554625+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)
2020-08-06T18:28:15.554626+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-08-06T18:28:15.554626+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)
2020-08-06T18:28:15.554626+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-08-06T18:28:15.554627+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
2020-08-06T18:28:15.554627+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-08-06T18:28:15.554628+00:00 app[web.1]: Emitted 'error' event on Server instance at:
2020-08-06T18:28:15.554628+00:00 app[web.1]: at emitErrorNT (net.js:1340:8)
2020-08-06T18:28:15.554629+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-08-06T18:28:15.554629+00:00 app[web.1]: code: 'EADDRINUSE',
2020-08-06T18:28:15.554629+00:00 app[web.1]: errno: 'EADDRINUSE',
2020-08-06T18:28:15.554630+00:00 app[web.1]: syscall: 'listen',
2020-08-06T18:28:15.554630+00:00 app[web.1]: address: '::',
2020-08-06T18:28:15.554631+00:00 app[web.1]: port: 43074
2020-08-06T18:28:15.554631+00:00 app[web.1]: }
2020-08-06T18:28:15.643665+00:00 heroku[web.1]: Process exited with status 1
2020-08-06T18:28:15.719470+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-06T18:28:15.721915+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-06T18:28:18.063014+00:00 heroku[web.1]: Starting process with command `node app.js`
2020-08-06T18:28:20.963100+00:00 app[web.1]: events.js:292
2020-08-06T18:28:20.963109+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-08-06T18:28:20.963110+00:00 app[web.1]: ^
2020-08-06T18:28:20.963110+00:00 app[web.1]:
2020-08-06T18:28:20.963110+00:00 app[web.1]: Error: listen EADDRINUSE: address already in use :::131252020-08-06T18:28:20.963111+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1313:16)
2020-08-06T18:28:20.963111+00:00 app[web.1]: at listenInCluster (net.js:1361:12)2020-08-06T18:28:20.963111+00:00 app[web.1]: at Server.listen (net.js:1447:7)
2020-08-06T18:28:20.963111+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2020-08-06T18:28:20.963112+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:146:5)
2020-08-06T18:28:20.963112+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)2020-08-06T18:28:20.963112+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-08-06T18:28:20.963113+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)2020-08-06T18:28:20.963117+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-08-06T18:28:20.963118+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)2020-08-06T18:28:20.963118+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-08-06T18:28:20.963118+00:00 app[web.1]: Emitted 'error' event on Server instance at:2020-08-06T18:28:20.963118+00:00 app[web.1]: at emitErrorNT (net.js:1340:8)
2020-08-06T18:28:20.963119+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {2020-08-06T18:28:20.963119+00:00 app[web.1]: code: 'EADDRINUSE',
2020-08-06T18:28:20.963119+00:00 app[web.1]: errno: 'EADDRINUSE',2020-08-06T18:28:20.963119+00:00 app[web.1]: syscall: 'listen',
2020-08-06T18:28:20.963119+00:00 app[web.1]: address: '::',2020-08-06T18:28:20.963120+00:00 app[web.1]: port: 13125
2020-08-06T18:28:20.963120+00:00 app[web.1]: }2020-08-06T18:28:21.012655+00:00 heroku[web.1]: Process exited with status 1
2020-08-06T18:28:21.056282+00:00 heroku[web.1]: State changed from starting to crashed2020-08-06T18:28:29.979419+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=glacial-garden-21504.herokuapp.com request_id=20e2dc90-d336-4df4-bf85-921f061bc1c8 fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
2020-08-06T18:28:30.848729+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=glacial-garden-21504.herokuapp.com request_id=f2e74a20-48ae-4dfc-bffb-ef19fd6a3d20 fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
2020-08-06T18:41:35.920695+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=glacial-garden-21504.herokuapp.com request_id=f9d2e233-529d-4b69-993c-72d1cb0a07f0 fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
2020-08-06T18:41:36.396586+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=glacial-garden-21504.herokuapp.com request_id=2b55782b-9c16-4577-a425-2197e1d089c3 fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
2020-08-06T18:49:42.523761+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-06T18:49:45.975358+00:00 heroku[web.1]: Starting process with command `node app.js`
2020-08-06T18:49:49.958428+00:00 heroku[web.1]: Process exited with status 1
2020-08-06T18:49:50.010996+00:00 heroku[web.1]: State changed from starting to crashed2020-08-06T18:49:49.868123+00:00 app[web.1]: events.js:292
2020-08-06T18:49:49.868203+00:00 app[web.1]: throw er; // Unhandled 'error' event2020-08-06T18:49:49.868208+00:00 app[web.1]: ^2020-08-06T18:49:49.868208+00:00 app[web.1]: 2020-08-06T18:49:49.868217+00:00 app[web.1]: Error: listen EADDRINUSE: address already in use :::41212
2020-08-06T18:49:49.868217+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1313:16)2020-08-06T18:49:49.868217+00:00 app[web.1]: at listenInCluster (net.js:1361:12)2020-08-06T18:49:49.868218+00:00 app[web.1]: at Server.listen (net.js:1447:7)2020-08-06T18:49:49.868222+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2020-08-06T18:49:49.868222+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:146:5)2020-08-06T18:49:49.868222+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)2020-08-06T18:49:49.868223+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)2020-08-06T18:49:49.868223+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)
2020-08-06T18:49:49.868223+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)2020-08-06T18:49:49.868227+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)2020-08-06T18:49:49.868228+00:00 app[web.1]: at internal/main/run_main_module.js:17:472020-08-06T18:49:49.868228+00:00 app[web.1]: Emitted 'error' event on Server instance at:
2020-08-06T18:49:49.868228+00:00 app[web.1]: at emitErrorNT (net.js:1340:8)
2020-08-06T18:49:49.868228+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-08-06T18:49:49.868232+00:00 app[web.1]: code: 'EADDRINUSE',
2020-08-06T18:49:49.868232+00:00 app[web.1]: errno: 'EADDRINUSE',
2020-08-06T18:49:49.868233+00:00 app[web.1]: syscall: 'listen',
2020-08-06T18:49:49.868233+00:00 app[web.1]: address: '::',
2020-08-06T18:49:49.868233+00:00 app[web.1]: port: 41212
2020-08-06T18:49:49.868233+00:00 app[web.1]: }
2020-08-06T19:17:44.469614+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=glacial-garden-21504.herokuapp.com request_id=84715403-a9ea-414d-ad04-e1b2b712f20b fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
2020-08-06T19:17:45.793877+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=glacial-garden-21504.herokuapp.com request_id=1e9c96ca-dab7-4ea5-b870-62b4be7194fc fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
^CTerminate batch job (Y/N)? ^C
The above message is being displayed
I am new to heroku and don't know much about it. It would we greatly appreciated if anyone walks me through the path of successfull app deployment.
You are calling app.listen two times. That isn't necessary. The EADDRINUSE error code tells you that you are trying to listen on an address that is already in use, which is what will happen if you call app.listen two times. Just call it once, like so:
let port = process.env.PORT;
if (port == null || port == "") { port = 3000; }
app.listen(port, function() {
console.log("Server has started successfully!");
});
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.