Error deploying node app to heroku - node.js

I'm relatively new to node, and have been having issues deploying a node web app to heroku... it seems to have to do with how I'm creating my mongoose connection in my server file. Here are the error logs I'm getting:
2016-01-06T00:41:30.384170+00:00 heroku[web.1]: State changed from starting to crashed
2016-01-06T00:43:56.191644+00:00 heroku[web.1]: State changed from crashed to starting
2016-01-06T00:43:57.774259+00:00 heroku[web.1]: Starting process with command `node server/server.js`
2016-01-06T00:44:00.138974+00:00 app[web.1]: listening on 4568
2016-01-06T00:44:00.172982+00:00 app[web.1]:
2016-01-06T00:44:00.172992+00:00 app[web.1]: /app/node_modules/mongoose/node_modules/mongodb/lib/server.js:236
2016-01-06T00:44:00.172994+00:00 app[web.1]: process.nextTick(function() { throw err; })
2016-01-06T00:44:00.172994+00:00 app[web.1]: ^
2016-01-06T00:44:00.172995+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:27017
2016-01-06T00:44:00.172996+00:00 app[web.1]: at Object.exports._errnoException (util.js:856:11)
2016-01-06T00:44:00.172997+00:00 app[web.1]: at exports._exceptionWithHostPort (util.js:879:20)
2016-01-06T00:44:00.172998+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
2016-01-06T00:44:00.968046+00:00 heroku[web.1]: Process exited with status 1
2016-01-06T00:44:00.983259+00:00 heroku[web.1]: State changed from starting to crashed
And here is a shell of my server file:
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var entryController = require('./entries/entryController.js');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static(__dirname + '/../client'));
mongoose.connect('mongodb://localhost');
console.log('listening on 4568');
app.listen(4568);
Any advice would be greatly appreciated, thanks!

You're trying to connect to localhost:
mongoose.connect('mongodb://localhost');
Localhost means "this computer." Your database is not running in the same container on Heroku as your node app, so instead you need to connect to where your database really is hosted.
You may want to read a tutorial like:
https://scotch.io/tutorials/use-mongodb-with-a-node-application-on-heroku

Related

I'm not able to start the mongo db server, getting the following error: [nodemon] app crashed - waiting for file changes before starting

This is server.js and .env file
I'm trying to start the server but it is throwing an error.
server.js
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
require('dotenv').config();
const app = express();
const port = process.env.PORT || 5000;
app.use(cors());
app.use(express.json());
const uri = process.env.ATLAS_URI;
mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true });
const connection = mongoose.connection;
connection.once('open',() => {
console.log("MongoDB database connection established successfully");
})
app.listen(port, () => {
console.log(`Server is running on port: ${port}`);
})
.env
ATLAS_URI = mongodb+srv://rnvsri:vastav123#cluster0.dgnw1.mongodb.net/test?retryWrites=true&w=majority
Issue:
In cmd, I'm giving the command nodemon server.js
but the server is not starting and it is throwing the following error.
nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
node:events:368
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::5000
at Server.setupListenHandle [as _listen2] (node:net:1334:16)
at listenInCluster (node:net:1382:12)
at Server.listen (node:net:1469:7)
at Function.listen (/Users/rnvsrivastava/mern/restaurant-reviews/backend/backend/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/Users/rnvsrivastava/mern/restaurant-reviews/backend/backend/server.js:20:6)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1361:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EADDRINUSE',
errno: -48,
syscall: 'listen',
address: '::',
port: 5000
}
[nodemon] app crashed - waiting for file changes before starting...
Can someone help?
port you are using is used by another process you can find it by
command
lsof -i :PORT and can kill using kill command
kill PID

Heroku cannot find mongoose module after deployment?

I have deployed a simple Nodejs app to Heroku and I keep getting an error in the application logs saying that the module "mongoose" cannot be found. I even provided a relative path instead of just saying require("mongoose"). The deployment succeeds and installs all the dependencies. The source code can be found here https://github.com/collinkleest/trim-io.
Here is the error log from heroku.
2020-10-17T02:01:42.000000+00:00 app[api]: Build started by user collinkleest#gmail.com
2020-10-17T02:01:59.000000+00:00 app[api]: Build succeeded
2020-10-17T02:01:59.493929+00:00 app[api]: Deploy af985be5 by user collinkleest#gmail.com
2020-10-17T02:01:59.493929+00:00 app[api]: Release v14 created by user collinkleest#gmail.com
2020-10-17T02:01:59.652847+00:00 heroku[web.1]: State changed from crashed to starting
2020-10-17T02:02:01.917601+00:00 heroku[web.1]: Starting process with command `npm start`
2020-10-17T02:02:04.175589+00:00 app[web.1]:
2020-10-17T02:02:04.175612+00:00 app[web.1]: > trim-io#0.0.1 start /app
2020-10-17T02:02:04.175612+00:00 app[web.1]: > node server.js
2020-10-17T02:02:04.175613+00:00 app[web.1]:
2020-10-17T02:02:04.369536+00:00 app[web.1]: internal/modules/cjs/loader.js:834
2020-10-17T02:02:04.369538+00:00 app[web.1]: throw err;
2020-10-17T02:02:04.369539+00:00 app[web.1]: ^
2020-10-17T02:02:04.369539+00:00 app[web.1]:
2020-10-17T02:02:04.369539+00:00 app[web.1]: Error: Cannot find module '../node_modules/mongoose'
2020-10-17T02:02:04.369540+00:00 app[web.1]: Require stack:
2020-10-17T02:02:04.369540+00:00 app[web.1]: - /app/models/urlEntity.js
2020-10-17T02:02:04.369541+00:00 app[web.1]: - /app/server.js
2020-10-17T02:02:04.369541+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
2020-10-17T02:02:04.369542+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:687:27)
2020-10-17T02:02:04.369542+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:903:19)
2020-10-17T02:02:04.369543+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2020-10-17T02:02:04.369543+00:00 app[web.1]: at Object.<anonymous> (/app/models/urlEntity.js:1:18)
2020-10-17T02:02:04.369543+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-10-17T02:02:04.369544+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-10-17T02:02:04.369544+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-10-17T02:02:04.369545+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-10-17T02:02:04.369545+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:903:19) {
2020-10-17T02:02:04.369545+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-10-17T02:02:04.369546+00:00 app[web.1]: requireStack: [ '/app/models/urlEntity.js', '/app/server.js' ]
2020-10-17T02:02:04.369546+00:00 app[web.1]: }
2020-10-17T02:02:04.389361+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-10-17T02:02:04.389827+00:00 app[web.1]: npm ERR! errno 1
2020-10-17T02:02:04.398788+00:00 app[web.1]: npm ERR! trim-io#0.0.1 start: `node server.js`
2020-10-17T02:02:04.399025+00:00 app[web.1]: npm ERR! Exit status 1
2020-10-17T02:02:04.399280+00:00 app[web.1]: npm ERR!
2020-10-17T02:02:04.399493+00:00 app[web.1]: npm ERR! Failed at the trim-io#0.0.1 start script.
2020-10-17T02:02:04.399722+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-10-17T02:02:04.420468+00:00 app[web.1]:
2020-10-17T02:02:04.420707+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-10-17T02:02:04.420857+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-10-17T02_02_04_400Z-debug.log
2020-10-17T02:02:04.487055+00:00 heroku[web.1]: Process exited with status 1
2020-10-17T02:02:04.554273+00:00 heroku[web.1]: State changed from starting to crashed
Here is my server.js for reference as well:
const express = require("express");
const UrlEntity = require("./models/urlEntity");
const mongoose = require("./node_modules/mongoose");
const urlEntity = require("./models/urlEntity");
const app = express();
require('dotenv').config();
const mongoUri = "mongodb+srv://" + process.env.MONGO_USR + ":" + process.env.MONGO_PASS + "#" + process.env.MONGO_URL + "/" + process.env.MONGO_DB + "?retryWrites=true&w=majority";
mongoose.connect(
mongoUri,
{ useNewUrlParser: true, useUnifiedTopology: true}
);
app.use(express.json());
app.use(express.static('public'));
async function checkIdExists(id){
let exists = await UrlEntity.exists({uniqueId: id});
return exists;
}
function generateId(){
let randomId = Math.random().toString(20).substr(2, 8);
while(!(checkIdExists(randomId))){
randomId = Math.random().toString(20).substr(2, 8);
}
return randomId;
}
// redirect functionality
app.get("/:id", async (req, res) => {
if (req.params.id !== null || req.params.id !== undefined){
let doc = await UrlEntity.findOne({uniqueId: req.params.id});
res.redirect(doc.targetUrl);
} else {
res.redirect('/');
}
});
// create new url
app.post("/create-url", async (req, res) => {
console.log("in post");
let id = generateId();
await UrlEntity.create({uniqueId: id,
targetUrl: req.body.url,
dateCreated: req.body.date});
res.send(`${req.protocol}://${req.get('host')}/${id}`);
});
app.listen(process.env.PORT || 5000, () => {console.log("Trim.io API Started")});
You put mongoose in your devDependencies, which will be removed at runtime. (Link from your code) You need to move it to dependencies so that it will be available at runtime.
try changing the const mongoose = require("./node_modules/mongoose")
back to const mongoose = require("mongoose");
Don't forget to set your environment variables MONGO_USR, MONGO_PASS e.t.c on heroku settings. Your server will not start if the environment variable is not set.
Lastly I advice you use a connection string like this mongodb+srv://user:password#cluster2.bftwu.mongodb.net/databaseName
without concatenating

Can't connect to MongoDB using environment variable for Heroku

My app works great when I hardcode the Mongo database connection, but when I try to use an environment variable, I get the errors in the log dump below.
I set the environment variable as follows:
$ heroku config:set MONGODB_URI='mongodb+srv://user:password#cluster0-ua7mc.mongodb.net/local_library?retryWrites=true'
(Note: I tried multiple iterations with and without quotes, and made sure the username and password were correct, etc.)
Here is the log dump:
2019-04-26T23:54:22.761573+00:00 heroku[web.1]: Restarting
2019-04-26T23:54:22.768606+00:00 heroku[web.1]: State changed from up to starting
2019-04-26T23:54:22.587447+00:00 app[api]: Release v14 created by user user#hotmail.com
2019-04-26T23:54:22.587447+00:00 app[api]: Set MONGODB_URI config vars by user user#hotmail.com
2019-04-26T23:54:23.508862+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-04-26T23:54:23.588782+00:00 heroku[web.1]: Process exited with status 143
2019-04-26T23:54:26.341850+00:00 heroku[web.1]: Starting process with command `npm start`
2019-04-26T23:54:28.837322+00:00 app[web.1]:
2019-04-26T23:54:28.837353+00:00 app[web.1]: > express-locallibrary-tutorial#0.0.0 start /app
2019-04-26T23:54:28.837356+00:00 app[web.1]: > node ./bin/www
2019-04-26T23:54:28.837357+00:00 app[web.1]:
2019-04-26T23:54:30.638883+00:00 heroku[web.1]: State changed from starting to up
2019-04-26T23:54:30.921094+00:00 app[web.1]: MongoDB Connection Error { MongoNetworkError: connection 5 to cluster0-shard-00-02-ua7mc.mongodb.net:27017 closed
2019-04-26T23:54:30.921142+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:352:9)
2019-04-26T23:54:30.921145+00:00 app[web.1]: at Object.onceWrapper (events.js:273:13)
2019-04-26T23:54:30.921146+00:00 app[web.1]: at TLSSocket.emit (events.js:182:13)
2019-04-26T23:54:30.921148+00:00 app[web.1]: at _handle.close (net.js:610:12)
2019-04-26T23:54:30.921150+00:00 app[web.1]: at TCP.done (_tls_wrap.js:386:7)
2019-04-26T23:54:30.921151+00:00 app[web.1]: name: 'MongoNetworkError',
2019-04-26T23:54:30.921153+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2019-04-26T23:54:30.921155+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {} }
2019-04-26T23:55:26.350787+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/catalog" host=immense-bucket-10578.herokuapp.com request_id=65fc54a9-5195-463b-a31a-f0ece0248800 fwd="47.136.227.118" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
2019-04-26T23:55:26.352964+00:00 app[web.1]: GET /catalog - - ms - -
Code dealing with Mongo Connection and environment variable is here:
var mongoose = require('mongoose');
var dev_db_url = 'mongodb+srv://user:password#cluster0-r92qb.mongodb.net/local_library?retryWrites=true';
var mongoDB = process.env.MONGODB_URI || dev_db_url;
mongoose.connect(mongoDB, {useNewUrlParser: true});
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
Many thanks in advance if any ideas!
SOLUTION: Changing Whitelist IP to 0.0.0.0/0 fixed the problem.
Try to set the variable via the dashboard. If still not connect then the problem should be with your mongo URI.

How to add Mlab url correctly to Heroku?

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.

Heroku Node.js - Permission Denied

I am trying to deploy a simple application to Heroku which makes use of the modules 'socket.io' and 'connect'. When I deploy the application I get a Permission Denied error and the application crashes. I am getting the port number from the environment property 'PORT'. I am configuring socket.io to use long polling rather than WebSockets (as I know they are not supported).
Can someone tell me what I'm doing wrong?
var io = require('socket.io'),
connect = require('connect');
var port = process.env.PORT || 5000;
var app = connect().use(connect.static('public')).listen(port);
var chat_room = io.listen(app);
chat_room.configure(function () {
chat_room.set("transports", ["xhr-polling"]);
chat_room.set("polling duration", 10);
});
chat_room.sockets.on('connection', function(socket){
socket.emit('entrance', {message:'Welcome to the chat room.'});
socket.on('disconnect', function(){
chat_room.sockets.emit('exit', {message:'A chatter has disconnected.'});
});
socket.on('chat', function(data){
chat_room.sockets.emit('chat',{message: '# ' + data.message});
});
chat_room.sockets.emit('entrance', {message: 'A new chatter is online.'});
});
Here is the error from the log:
2013-02-01T04:24:04+00:00 app[web.1]: Error: EACCES, Permission denied
2013-02-01T04:24:04+00:00 app[web.1]: at Server.listen (net.js:1063:20)
2013-02-01T04:24:04+00:00 app[web.1]: node.js:134
2013-02-01T04:24:04+00:00 app[web.1]: at Server._doListen (net.js:1098:5)
2013-02-01T04:24:04+00:00 app[web.1]: at net.js:1069:14
2013-02-01T04:24:04+00:00 app[web.1]: at Object.lookup (dns.js:153:45)
2013-02-01T04:24:04+00:00 app[web.1]: at Object.listen (/app/node_modules/socket.io/lib/socket.io.js:67:12)
2013-02-01T04:24:04+00:00 app[web.1]: at Object.<anonymous> (/app/main.js:8:20)
2013-02-01T04:24:04+00:00 app[web.1]: at Module.load (module.js:336:31)
2013-02-01T04:24:04+00:00 app[web.1]: at Module._compile (module.js:404:26)
2013-02-01T04:24:04+00:00 app[web.1]: at Function._load (module.js:297:12)
2013-02-01T04:24:04+00:00 app[web.1]: at Object..js (module.js:410:10)
2013-02-01T04:24:06+00:00 heroku[web.1]: Process exited with status 1
2013-02-01T04:24:06+00:00 heroku[web.1]: State changed from starting to crashed
Thanks!

Resources