I'm trying to deploy a small node app to Heroku with Mlab database - but i can't figure out what's wrong... i'm getting errors in the Heroku logs that i guess they are related to the connection...be cause without it - it's working.
Here are my steps and code :
I've created app in Heroku - followed the instructions
In heroku resources i've added Mlab addon and in Config Variables - i've changed the MONGODB_URI to my db.
I've set the MONGODB_URI to the connect url...
Here is the server :
var express = require('express');
var cors = require('cors')
var app = express();
var morgan = require('morgan');
app.use(morgan('dev'));
var port = process.env.PORT || 3007;
var mongoose = require('mongoose');
//MONGOLAB_URI='mongodb://foo:fff#ds163612.mlab.com:63615/cars';
mongoose.connect(MONGOLAB_URI, function (error) {
if (error) console.error(error);
else console.log('mongo connected');
});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log("DB connection alive");
});
// var User = require('./model/user');
var Message = require('./model/message');
var Car = require('./model/car');
var router = express.Router();
app.get('/',cors(),function(req, res) {
Car.find(function(err, cars) {
if (err)
res.send(err);
res.json(cars);
});
});
app.get('/messages',cors(),function(req, res) {
Message.find(function(err, messages) {
if (err)
res.send(err);
res.json(messages);
});
});
app.get('/cars',cors(),function(req, res) {
Car.find(function(err, cars) {
if (err)
res.send(err);
res.json(cars);
});
});
app.listen(port);
console.log('Magic happens on port ' + port);
And here is the logs :
2018-02-16T08:28:52.841304+00:00 app[api]: Release v31 created by user foo#gmail.com
2018-02-16T08:28:52.841304+00:00 app[api]: Deploy 5f779472 by user foo#gmail.com
2018-02-16T08:28:42.000000+00:00 app[api]: Build succeeded
2018-02-16T08:28:53.326343+00:00 heroku[web.1]: Restarting
2018-02-16T08:28:53.327265+00:00 heroku[web.1]: State changed from up to starting
2018-02-16T08:28:54.189659+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-02-16T08:28:54.296051+00:00 heroku[web.1]: Process exited with status 143
2018-02-16T08:28:55.360118+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-16T08:28:57.304833+00:00 app[web.1]:
2018-02-16T08:28:57.304857+00:00 app[web.1]: > react-deploy-test#1.0.0 start /app
2018-02-16T08:28:57.304861+00:00 app[web.1]: > node server.js
2018-02-16T08:28:57.304862+00:00 app[web.1]:
2018-02-16T08:28:57.847783+00:00 app[web.1]: Magic happens on port 27591
2018-02-16T08:28:57.941605+00:00 app[web.1]: DB connection alive
2018-02-16T08:28:57.941955+00:00 app[web.1]: mongo connected
2018-02-16T08:28:58.502415+00:00 heroku[web.1]: State changed from starting to up
2018-02-16T08:31:01.000000+00:00 app[api]: Build started by user foo#gmail.com
2018-02-16T08:31:11.871346+00:00 app[api]: Deploy 30ad9492 by user foo#gmail.com
2018-02-16T08:31:11.871346+00:00 app[api]: Release v32 created by user foo#gmail.com
2018-02-16T08:31:01.000000+00:00 app[api]: Build succeeded
2018-02-16T08:31:13.173487+00:00 heroku[web.1]: Restarting
2018-02-16T08:31:13.174022+00:00 heroku[web.1]: State changed from up to starting
2018-02-16T08:31:14.080217+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-02-16T08:31:14.203672+00:00 heroku[web.1]: Process exited with status 143
2018-02-16T08:31:15.886400+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-16T08:31:18.456384+00:00 app[web.1]:
2018-02-16T08:31:18.456429+00:00 app[web.1]: > react-deploy-test#1.0.0 start /app
2018-02-16T08:31:18.456431+00:00 app[web.1]: > node server.js
2018-02-16T08:31:18.456433+00:00 app[web.1]:
2018-02-16T08:31:19.161125+00:00 app[web.1]: Magic happens on port 45873
2018-02-16T08:31:19.164986+00:00 app[web.1]: TypeError: Parameter "url" must be a string, not undefined
2018-02-16T08:31:19.164990+00:00 app[web.1]: at Url.parse (url.js:103:11)
2018-02-16T08:31:19.164992+00:00 app[web.1]: at Object.urlParse [as parse] (url.js:97:13)
2018-02-16T08:31:19.164994+00:00 app[web.1]: at module.exports (/app/node_modules/mongodb/lib/url_parser.js:13:23)
2018-02-16T08:31:19.164997+00:00 app[web.1]: at new Promise (<anonymous>)
2018-02-16T08:31:19.164995+00:00 app[web.1]: at Promise (/app/node_modules/mongoose/lib/connection.js:332:5)
2018-02-16T08:31:19.164999+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:331:19)
2018-02-16T08:31:19.165001+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:206:15)
2018-02-16T08:31:19.165002+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:14:10)
2018-02-16T08:31:19.165004+00:00 app[web.1]: at Module._compile (module.js:643:30)
2018-02-16T08:31:19.165006+00:00 app[web.1]: at Object.Module._extensions..js (module.js:654:10)
2018-02-16T08:31:19.165007+00:00 app[web.1]: at Module.load (module.js:556:32)
2018-02-16T08:31:19.165009+00:00 app[web.1]: at tryModuleLoad (module.js:499:12)
2018-02-16T08:31:19.165010+00:00 app[web.1]: at Function.Module._load (module.js:491:3)
2018-02-16T08:31:19.165012+00:00 app[web.1]: at Function.Module.runMain (module.js:684:10)
2018-02-16T08:31:19.165014+00:00 app[web.1]: at startup (bootstrap_node.js:187:16)
2018-02-16T08:31:19.165015+00:00 app[web.1]: at bootstrap_node.js:608:3
2018-02-16T08:31:19.167672+00:00 app[web.1]: (node:20) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Parameter "url" must be a string, not undefined
2018-02-16T08:31:19.167809+00:00 app[web.1]: (node:20) [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.
2018-02-16T08:31:19.566292+00:00 heroku[web.1]: State changed from starting to up
2018-02-16T08:32:28.000000+00:00 app[api]: Build started by user foo#gmail.com
2018-02-16T08:32:40.526330+00:00 app[api]: Deploy 3fe92549 by user foo#gmail.com
2018-02-16T08:32:40.526330+00:00 app[api]: Release v33 created by user foo#gmail.com
2018-02-16T08:32:41.917774+00:00 heroku[web.1]: Restarting
2018-02-16T08:32:41.919583+00:00 heroku[web.1]: State changed from up to starting
2018-02-16T08:32:28.000000+00:00 app[api]: Build succeeded
2018-02-16T08:32:42.673705+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-02-16T08:32:42.777505+00:00 heroku[web.1]: Process exited with status 143
2018-02-16T08:32:45.105809+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-16T08:32:47.705781+00:00 app[web.1]:
2018-02-16T08:32:47.705800+00:00 app[web.1]: > react-deploy-test#1.0.0 start /app
2018-02-16T08:32:47.705802+00:00 app[web.1]: > node server.js
2018-02-16T08:32:47.705804+00:00 app[web.1]:
2018-02-16T08:32:49.079895+00:00 app[web.1]: Magic happens on port 48220
2018-02-16T08:32:49.083923+00:00 app[web.1]: Error: Username contains an illegal unescaped character
2018-02-16T08:32:49.083926+00:00 app[web.1]: at parseConnectionString (/app/node_modules/mongodb/lib/url_parser.js:274:11)
2018-02-16T08:32:49.083929+00:00 app[web.1]: at parseHandler (/app/node_modules/mongodb/lib/url_parser.js:113:14)
2018-02-16T08:32:49.083932+00:00 app[web.1]: at Promise (/app/node_modules/mongoose/lib/connection.js:332:5)
2018-02-16T08:32:49.083930+00:00 app[web.1]: at module.exports (/app/node_modules/mongodb/lib/url_parser.js:19:12)
2018-02-16T08:32:49.083934+00:00 app[web.1]: at new Promise (<anonymous>)
2018-02-16T08:32:49.083936+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:331:19)
2018-02-16T08:32:49.083938+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:206:15)
2018-02-16T08:32:49.083940+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:14:10)
2018-02-16T08:32:49.083942+00:00 app[web.1]: at Module._compile (module.js:643:30)
2018-02-16T08:32:49.083944+00:00 app[web.1]: at Object.Module._extensions..js (module.js:654:10)
2018-02-16T08:32:49.083945+00:00 app[web.1]: at Module.load (module.js:556:32)
2018-02-16T08:32:49.083947+00:00 app[web.1]: at tryModuleLoad (module.js:499:12)
2018-02-16T08:32:49.083949+00:00 app[web.1]: at Function.Module._load (module.js:491:3)
2018-02-16T08:32:49.083951+00:00 app[web.1]: at Function.Module.runMain (module.js:684:10)
2018-02-16T08:32:49.083952+00:00 app[web.1]: at startup (bootstrap_node.js:187:16)
2018-02-16T08:32:49.083954+00:00 app[web.1]: at bootstrap_node.js:608:3
2018-02-16T08:32:49.086111+00:00 app[web.1]: (node:20) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Username contains an illegal unescaped character
2018-02-16T08:32:49.086216+00:00 app[web.1]: (node:20) [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.
2018-02-16T08:32:49.681542+00:00 heroku[web.1]: State changed from starting to up
2018-02-16T08:34:01.000000+00:00 app[api]: Build started by user foo#gmail.com
2018-02-16T08:34:12.813906+00:00 heroku[web.1]: Restarting
2018-02-16T08:34:12.814458+00:00 heroku[web.1]: State changed from up to starting
2018-02-16T08:34:12.577577+00:00 app[api]: Release v34 created by user foo#gmail.com
2018-02-16T08:34:12.577577+00:00 app[api]: Deploy d3e91a9d by user foo#gmail.com
2018-02-16T08:34:01.000000+00:00 app[api]: Build succeeded
2018-02-16T08:34:13.936150+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-02-16T08:34:14.047866+00:00 heroku[web.1]: Process exited with status 143
2018-02-16T08:34:16.448867+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-16T08:34:19.712447+00:00 app[web.1]:
2018-02-16T08:34:19.712477+00:00 app[web.1]: > react-deploy-test#1.0.0 start /app
2018-02-16T08:34:19.712479+00:00 app[web.1]: > node server.js
2018-02-16T08:34:19.712481+00:00 app[web.1]:
2018-02-16T08:34:20.739041+00:00 app[web.1]: Magic happens on port 13708
2018-02-16T08:34:20.859749+00:00 app[web.1]: DB connection alive
2018-02-16T08:34:20.860347+00:00 app[web.1]: mongo connected
2018-02-16T08:34:21.269185+00:00 heroku[web.1]: State changed from starting to up
2018-02-16T08:34:12.813906+00:00 heroku[web.1]: Restarting
2018-02-16T08:34:12.814458+00:00 heroku[web.1]: State changed from up to starting
2018-02-16T08:34:12.577577+00:00 app[api]: Release v34 created by user foo#gmail.com
2018-02-16T08:34:12.577577+00:00 app[api]: Deploy d3e91a9d by user foo#gmail.com
2018-02-16T08:34:01.000000+00:00 app[api]: Build succeeded
2018-02-16T08:34:13.936150+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-02-16T08:34:14.047866+00:00 heroku[web.1]: Process exited with status 143
2018-02-16T08:34:16.448867+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-16T08:34:19.712447+00:00 app[web.1]:
2018-02-16T08:34:19.712477+00:00 app[web.1]: > react-deploy-test#1.0.0 start /app
2018-02-16T08:34:19.712479+00:00 app[web.1]: > node server.js
2018-02-16T08:34:19.712481+00:00 app[web.1]:
2018-02-16T08:34:20.739041+00:00 app[web.1]: Magic happens on port 13708
2018-02-16T08:34:20.859749+00:00 app[web.1]: DB connection alive
2018-02-16T08:34:20.860347+00:00 app[web.1]: mongo connected
2018-02-16T08:34:21.269185+00:00 heroku[web.1]: State changed from starting to up
Regarding: Error: Username contains an illegal unescaped character Just answering this in case anybody else runs into this problem. I had this problem the other day and it turned out that I had accidentally put a line break into my environmental variable string when I copy/pasted. That's definitely something to try when you are looking for a fix.
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 am deploying a fullstack react/express app to Heroku, it has managed to deploy. There are multiple errors in the Heroku logs which I have cannot seem to understand/figure out. I also have a Procfile with web: node server.js
I have tried to clear cache - delete node_modules and package.json then npm install again but this has not made a difference.
Heroku Logs
2020-11-15T13:08:12.713935+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:08:12.713935+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:08:12.713935+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:08:12.783289+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:08:12.818062+00:00 heroku[web.1]: State changed from starting to crashed
2020-11-15T13:08:12.826070+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-15T13:08:21.448256+00:00 heroku[web.1]: Starting process with command `node server.js`
2020-11-15T13:08:24.324135+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:669
2020-11-15T13:08:24.324170+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2020-11-15T13:08:24.324175+00:00 app[web.1]: ^
2020-11-15T13:08:24.324175+00:00 app[web.1]:
2020-11-15T13:08:24.324180+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2020-11-15T13:08:24.324185+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:669:11)
2020-11-15T13:08:24.324185+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-11-15T13:08:24.324190+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
2020-11-15T13:08:24.324190+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-11-15T13:08:24.324190+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:18:10)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-11-15T13:08:24.324191+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:08:24.324192+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:08:24.324196+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:08:24.418110+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:08:24.454083+00:00 heroku[web.1]: State changed from starting to crashed
2020-11-15T13:23:24.786742+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=obscure-journey-43421.herokuapp.com request_id=aa6c54d3-cfe3-4f74-b4c5-93018f00ba97 fwd="84.9.66.95" dyno= connect= service= status=503 bytes= protocol=https
2020-11-15T13:23:26.240301+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=obscure-journey-43421.herokuapp.com request_id=ec07ad1c-091f-4e53-b50d-9632b66dd2d4 fwd="84.9.66.95" dyno= connect= service= status=503 bytes= protocol=https
2020-11-15T13:27:28.000000+00:00 app[api]: Build started by user peterjameslewis4#hotmail.com
2020-11-15T13:29:08.458958+00:00 app[api]: Deploy 12d81f3b by user peterjameslewis4#hotmail.com
2020-11-15T13:29:08.458958+00:00 app[api]: Release v12 created by user peterjameslewis4#hotmail.com
2020-11-15T13:29:08.625747+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-15T13:29:09.000000+00:00 app[api]: Build succeeded
2020-11-15T13:29:17.927953+00:00 heroku[web.1]: Starting process with command `npm start`
2020-11-15T13:29:20.083139+00:00 app[web.1]:
2020-11-15T13:29:20.083155+00:00 app[web.1]: > movie-database#1.0.0 start /app
2020-11-15T13:29:20.083155+00:00 app[web.1]: > node server.js
2020-11-15T13:29:20.083155+00:00 app[web.1]:
2020-11-15T13:29:20.795200+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:669
2020-11-15T13:29:20.795248+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2020-11-15T13:29:20.795250+00:00 app[web.1]: ^
2020-11-15T13:29:20.795250+00:00 app[web.1]:
2020-11-15T13:29:20.795251+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2020-11-15T13:29:20.795252+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:669:11)
2020-11-15T13:29:20.795254+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-11-15T13:29:20.795254+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
2020-11-15T13:29:20.795255+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-11-15T13:29:20.795255+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:18:10)
2020-11-15T13:29:20.795255+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-11-15T13:29:20.795256+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-11-15T13:29:20.795256+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-11-15T13:29:20.795256+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:29:20.795257+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:29:20.795258+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:29:20.810114+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-11-15T13:29:20.810451+00:00 app[web.1]: npm ERR! errno 1
2020-11-15T13:29:20.817598+00:00 app[web.1]: npm ERR! movie-database#1.0.0 start: `node server.js`
2020-11-15T13:29:20.817850+00:00 app[web.1]: npm ERR! Exit status 1
2020-11-15T13:29:20.818099+00:00 app[web.1]: npm ERR!
2020-11-15T13:29:20.818312+00:00 app[web.1]: npm ERR! Failed at the movie-database#1.0.0 start script.
2020-11-15T13:29:20.818490+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-11-15T13:29:20.827750+00:00 app[web.1]:
2020-11-15T13:29:20.828041+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-11-15T13:29:20.828210+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-11-15T13_29_20_819Z-debug.log
2020-11-15T13:29:20.877545+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:29:20.913439+00:00 heroku[web.1]: State changed from starting to crashed
2020-11-15T13:29:20.917070+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-15T13:29:33.460653+00:00 heroku[web.1]: Starting process with command `npm start`
2020-11-15T13:29:36.844587+00:00 app[web.1]:
2020-11-15T13:29:36.844630+00:00 app[web.1]: > movie-database#1.0.0 start /app
2020-11-15T13:29:36.844631+00:00 app[web.1]: > node server.js
2020-11-15T13:29:36.844631+00:00 app[web.1]:
2020-11-15T13:29:38.011159+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:669
2020-11-15T13:29:38.011219+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2020-11-15T13:29:38.011220+00:00 app[web.1]: ^
2020-11-15T13:29:38.011220+00:00 app[web.1]:
2020-11-15T13:29:38.011224+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2020-11-15T13:29:38.011224+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:669:11)
2020-11-15T13:29:38.011225+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-11-15T13:29:38.011226+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:9:12)
2020-11-15T13:29:38.011226+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-11-15T13:29:38.011226+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:18:10)
2020-11-15T13:29:38.011227+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-11-15T13:29:38.011227+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-11-15T13:29:38.011227+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-11-15T13:29:38.011228+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-11-15T13:29:38.011228+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2020-11-15T13:29:38.011229+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-11-15T13:29:38.046555+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-11-15T13:29:38.047758+00:00 app[web.1]: npm ERR! errno 1
2020-11-15T13:29:38.059446+00:00 app[web.1]: npm ERR! movie-database#1.0.0 start: node server.js
2020-11-15T13:29:38.059681+00:00 app[web.1]: npm ERR! Exit status 1
2020-11-15T13:29:38.059955+00:00 app[web.1]: npm ERR!
2020-11-15T13:29:38.060192+00:00 app[web.1]: npm ERR! Failed at the movie-database#1.0.0 start script.
2020-11-15T13:29:38.060432+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-11-15T13:29:38.096793+00:00 app[web.1]:
2020-11-15T13:29:38.097273+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-11-15T13:29:38.097587+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-11-15T13_29_38_061Z-debug.log
2020-11-15T13:29:38.193702+00:00 heroku[web.1]: Process exited with status 1
2020-11-15T13:29:38.242866+00:00 heroku[web.1]: State changed from starting to crashed
Server.js
const express = require('express');
const app = express();
const path = require('path');
const cors = require('cors');
const port = process.env.PORT || 5000;
const dotenv = require('dotenv');
const mongoose = require('mongoose');
// Auth Routes
const authRoute = require('./routes/auth');
dotenv.config();
//Connect to DB
mongoose.connect(process.env.DB_CONNECT,
{ useNewUrlParser: true, useUnifiedTopology: true },
() => console.log('connected to DB!')
);
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'client/build/')));
// Middleware
app.use(express.json());
app.use(cors());
// Put all API endpoints under '/api'
app.use('/api', authRoute)
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/build/index.html'));
});
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});
Package.json
{
"name": "movie-database",
"version": "1.0.0",
"description": "Small application created with React.js, react router and the movie database to showcase all latest, upcoming and most popular movies.",
"main": "server.js",
"scripts": {
"start": "node server.js",
"heroku-postbuild": "cd client && npm install && npm run build"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"joi": "^17.3.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.20",
"mongoose": "^5.10.12",
"nodemon": "^2.0.6",
"password-generator": "^2.3.2",
"serve": "^11.3.2"
}
}
I cannot figure out what is going wrong?
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.
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.
My app works locally. I added all that I thought was necessary for Heroku
Procfile
web: node app.js
package.json
{
"name": "HipsterMatch",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "nodemon app.js"
},
"dependencies": {
"express": "3.1.0",
"jade": "*",
"mongodb": "*",
"nodemon": "0.7.10",
"passport": "*",
"passport-local": "*",
"passport-facebook": "*",
"mongoose": "~3.6.4",
"connect-flash": "*"
},
"engines": {
"node": "0.10.1",
"npm": "1.3.14"
}
}
Here are my logs
2013-12-27T08:40:29.457548+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=hipsterlove.herokuapp.com fwd="162.205.69.18" dyno= connect= service= status=503 bytes=
2013-12-27T08:44:38.166741+00:00 heroku[api]: Add mongohq:sandbox add-on by jgallardo720#gmail.com
2013-12-27T08:44:38.186021+00:00 heroku[api]: Release v5 created by jgallardo720#gmail.com
2013-12-27T08:44:38.327041+00:00 heroku[web.1]: State changed from crashed to starting
2013-12-27T08:44:40.396197+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-12-27T08:44:42.090303+00:00 app[web.1]: Express server listening on port 37441
2013-12-27T08:44:42.092470+00:00 app[web.1]:
2013-12-27T08:44:42.092672+00:00 app[web.1]: events.js:72
2013-12-27T08:44:42.092911+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-12-27T08:44:42.092911+00:00 app[web.1]: ^
2013-12-27T08:44:42.095509+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-12-27T08:44:42.095509+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-12-27T08:44:42.095509+00:00 app[web.1]: at EventEmitter.emit (events.js:106:17)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at EventEmitter.emit (events.js:98:17)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-12-27T08:44:42.095509+00:00 app[web.1]: at net.js:426:14
2013-12-27T08:44:43.403162+00:00 heroku[web.1]: Process exited with status 8
2013-12-27T08:44:43.421294+00:00 heroku[web.1]: State changed from starting to crashed
2013-12-27T08:45:03.209570+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=hipsterlove.herokuapp.com fwd="162.205.69.18" dyno= connect= service= status=503 bytes=
2013-12-27T08:47:32.961418+00:00 heroku[api]: Add papertrail:choklad add-on by jgallardo720#gmail.com
2013-12-27T08:47:33.079955+00:00 heroku[api]: Release v6 created by jgallardo720#gmail.com
2013-12-27T08:47:33.710788+00:00 heroku[web.1]: State changed from crashed to starting
2013-12-27T08:47:36.186033+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-12-27T08:47:37.958627+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-12-27T08:47:37.958627+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-12-27T08:47:37.958627+00:00 app[web.1]: at EventEmitter.emit (events.js:106:17)
2013-12-27T08:47:37.954398+00:00 app[web.1]: ^
2013-12-27T08:47:37.949510+00:00 app[web.1]: Express server listening on port 32125
2013-12-27T08:47:37.952974+00:00 app[web.1]:
2013-12-27T08:47:37.953554+00:00 app[web.1]: events.js:72
2013-12-27T08:47:37.954045+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-12-27T08:47:37.958627+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-12-27T08:47:37.958627+00:00 app[web.1]: at EventEmitter.emit (events.js:98:17)
2013-12-27T08:47:37.958627+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-12-27T08:47:37.958627+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-12-27T08:47:37.958627+00:00 app[web.1]: at net.js:426:14
2013-12-27T08:47:37.958627+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
2013-12-27T08:47:39.133359+00:00 heroku[web.1]: State changed from starting to crashed
2013-12-27T08:47:39.134204+00:00 heroku[web.1]: State changed from crashed to starting
2013-12-27T08:47:39.120176+00:00 heroku[web.1]: Process exited with status 8
2013-12-27T08:47:41.463835+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-12-27T08:47:42.782433+00:00 app[web.1]: Express server listening on port 7709
2013-12-27T08:47:42.784187+00:00 app[web.1]:
2013-12-27T08:47:42.784508+00:00 app[web.1]: events.js:72
2013-12-27T08:47:42.784983+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-12-27T08:47:42.784983+00:00 app[web.1]: ^
2013
-12-27T08:47:42.787164+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-12-27T08:47:42.787164+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at EventEmitter.emit (events.js:106:17)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at EventEmitter.emit (events.js:98:17)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-12-27T08:47:42.787164+00:00 app[web.1]: at net.js:426:14
2013-12-27T08:47:42.787164+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
2013-12-27T08:47:44.091837+00:00 heroku[web.1]: Process exited with status 8
2013-12-27T08:47:44.093316+00:00 heroku[web.1]: State changed from starting to crashed
2013-12-27T08:50:30+00:00 heroku[slug-compiler]: Slug compilation started
2013-12-27T08:50:55.506146+00:00 heroku[api]: Deploy 36c405b by jgallardo720#gmail.com
2013-12-27T08:50:55.532599+00:00 heroku[api]: Release v7 created by jgallardo720#gmail.com
2013-12-27T08:50:55+00:00 heroku[slug-compiler]: Slug compilation finished
2013-12-27T08:50:55.924898+00:00 heroku[web.1]: State changed from crashed to starting
2013-12-27T08:50:57.601471+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-12-27T08:50:58.821299+00:00 app[web.1]: Express server listening on port 44602
2013-12-27T08:50:58.823409+00:00 app[web.1]: events.js:72
2013-12-27T08:50:58.823687+00:00 app[web.1]: ^
2013-12-27T08:50:58.823080+00:00 app[web.1]:
2013-12-27T08:50:58.823687+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-12-27T08:50:58.826090+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-12-27T08:50:58.826090+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-12-27T08:50:58.826090+00:00 app[web.1]: at EventEmitter.emit (events.js:98:17)
2013-12-27T08:50:58.826090+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-12-27T08:50:58.826090+00:00 app[web.1]: at EventEmitter.emit (events.js:106:17)
2013-12-27T08:50:58.826090+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-12-27T08:50:58.826090+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-12-27T08:50:58.826090+00:00 app[web.1]: at net.js:426:14
2013-12-27T08:50:58.826090+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
2013-12-27T08:50:59.977120+00:00 heroku[web.1]: Process exited with status 8
2013-12-27T08:50:59.998919+00:00 heroku[web.1]: State changed from starting to crashed
2013-12-27T08:57:32.833792+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=hipsterlove.herokuapp.com fwd="174.251.209.112" dyno= connect= service= status=503 bytes=
2013-12-27T09:01:35.385263+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-12-27T09:01:36.760608+00:00 app[web.1]: events.js:72
2013-12-27T09:01:36.758539+00:00 app[web.1]: Express server listening on port 4749
2013-12-27T09:01:36.760891+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-12-27T09:01:36.760257+00:00 app[web.1]:
2013-12-27T09:01:36.761120+00:00 app[web.1]: ^
2013-12-27T09:01:36.763625+00:00 app[web.1]: at EventEmitter.emit (events.js:98:17)
2013-12-27T09:01:36.763625+00:00 app[web.1]: at EventEmitter.emit (events.js:106:17)
2013-12-27T09:01:36.763625+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-12-27T09:01:36.763625+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-12-27T09:01:36.763625+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-12-27T09:01:36.763625+00:00 app[web.1]: at net.js:426:14
2013-12-27T09:01:36.763625+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
2013-12-27T09:01:36.763625+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-12-27T09:01:36.763625+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-12-27T09:01:37.955733+00:00 heroku[web.1]: Process exited with status 8
2013-12-27T09:01:37.987115+00:00 heroku[web.1]: State changed from starting to crashed
2013-12-27T09:01:33.253022+00:00 heroku[web.1]: State changed from crashed to starting
It looks like in prod you are referencing your local mongoDB instance:
Error: failed to connect to [localhost:27017]
I imagine you've hardcoded these values...
The recommended way of handling connection strings like this that change from environment to environment is to use environment variables (http://12factor.net/config).
So you'll need to do the following (if you haven't already).
1) Set up a mongo instance in the cloud (MongoHQ, mongoLab, etc) (heroku makes this fairly easy).
2) If heroku hasn't set the env variables for the connection strings you'll need to do that.
To list your env vars (enter this on the command line):
heroku config -a name_of_your_heroku_app
To set your env vars:
heroku config:set MONGO_URL=somethingGoesHere -a name_of_your_heroku_app
Then in your node code you can reference that value like so:
var url = process.env.MONGO_URL;
To set your env variables locally, create a .env file in the root of your app. Running foreman start will run your procfile as well as loading the .env variables into memory.