Node & Redis Application Error on Heroku - node.js

I am new on Heroku & Node so please bear with me. I deployed my working chatting app(on localhost) to Heroku but can't open the Heroku app.
Can anyone help me how to fix this issue?
I looked at some similar questions on stackoverflow and did heroku config:add REDISCLOUD_URL='redis_cloud_url' and heroku config:add NODE_ENV='production' but those didn't work.
Here is my heroku log.
2015-04-11T19:42:35.568690+00:00 heroku[api]: Deploy 0244dd7 by MYMAIL#gmail.com
2015-04-11T19:42:38.004491+00:00 heroku[web.1]: Starting process with command `node app.js`
2015-04-11T19:42:39.182617+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2015-04-11T19:42:39.182639+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2015-04-11T19:42:39.793252+00:00 app[web.1]: events.js:85
2015-04-11T19:42:39.793258+00:00 app[web.1]: throw er; // Unhandled 'error' event
2015-04-11T19:42:39.793260+00:00 app[web.1]: ^
2015-04-11T19:42:39.793262+00:00 app[web.1]: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
2015-04-11T19:42:39.793264+00:00 app[web.1]: at RedisClient.on_error (/app/node_modules/redis/index.js:196:24)
2015-04-11T19:42:39.793266+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/redis/index.js:106:14)
2015-04-11T19:42:39.793268+00:00 app[web.1]: at Socket.emit (events.js:107:17)
2015-04-11T19:42:39.793270+00:00 app[web.1]: at net.js:459:14
2015-04-11T19:42:39.793271+00:00 app[web.1]: at process._tickCallback (node.js:355:11)
2015-04-11T19:42:40.546881+00:00 heroku[web.1]: State changed from starting to crashed

Okay I know the problem actually, the issue is that you're using redis cloud, so redis is not running on 127.0.0.1
Have a look at the official documentation on Heroku; you must not set REDISCLOUD_URL to redis_cloud_url, you must let Heroku set it to your account's REDISCLOUD_URL, that you can get by doing this in your terminal
heroku config:get REDISCLOUD_URL
It should return something like this ;
http://rediscloud:password#hostname:port
If it returns something without this format then the addon is not properly configured / activated for your app.
And your code to connect to redis should look like this :
var redis = require('redis');
var url = require('url');
var redisURL = url.parse(process.env.REDISCLOUD_URL);
var client = redis.createClient(redisURL.port, redisURL.hostname, {no_ready_check: true});
client.auth(redisURL.auth.split(":")[1]);

I use Heroku Redis, not Redis To Go and also had such an issue. However I solved the issue by changing the way Redis client is initialized, previously I had following code:
const
redisOptions = require('./redisOptions'),
redis = require('redis'),
redisClient = redis.createClient(redisOptions);
now I removed url parameter from redisOptions and then add it to createClient method, i.e.:
const
redisOptions = require('./redisOptions'),
redis = require('redis'),
redisClient = redis.createClient(REDIS_URL, redisOptions);
then the error was fixed. Really not sure why it is working with no issues on my local environment but I need this fix on Heroku.

Related

Selenium on heroku DevToolsActivePort file doesn't exist

So, I'm trying to deploy a node, selenium app to heroku.
This is how my code looks
let options = new Options();
options.setChromeBinaryPath(process.env.GOOGLE_CHROME_BIN);
options.addArguments("--headless");
options.addArguments("--start-maximized");
options.addArguments("--headless");
options.addArguments("--disable-dev-usage");
options.addArguments("--window-size=1920,1080");
options.addArguments("--ignore-certificate-errors");
options.addArguments("--allow-running-insecure-content");
options.setUserPreferences({"prefs":{"useAutomationExtension": false}});
let serviceBuilder = new ServiceBuilder();
console.log("initialized serice builder");
let driver = new Builder(process.env.CHROME_EXECUTABLE_PATH)
.forBrowser(Browser.CHROME)
.setChromeOptions(options)
.setChromeService(serviceBuilder)
.build();
This throws an error on the heroku logs like so
2021-05-18T05:42:15.372134+00:00 app[web.1]: /app/node_modules/selenium-webdriver/lib/error.js:517
2021-05-18T05:42:15.372174+00:00 app[web.1]: let err = new ctor(data.message)
2021-05-18T05:42:15.372175+00:00 app[web.1]: ^
2021-05-18T05:42:15.372176+00:00 app[web.1]:
2021-05-18T05:42:15.372176+00:00 app[web.1]: WebDriverError: unknown error: Chrome failed to start: crashed.
2021-05-18T05:42:15.372177+00:00 app[web.1]: (unknown error: DevToolsActivePort file doesn't exist)
2021-05-18T05:42:15.372180+00:00 app[web.1]: (The process started from chrome location /app/.apt/opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
2021-05-18T05:42:15.372181+00:00 app[web.1]: at Object.throwDecodedError (/app/node_modules/selenium-webdriver/lib/error.js:517:15)
2021-05-18T05:42:15.372181+00:00 app[web.1]: at parseHttpResponse (/app/node_modules/selenium-webdriver/lib/http.js:642:13)
2021-05-18T05:42:15.372181+00:00 app[web.1]: at Executor.execute (/app/node_modules/selenium-webdriver/lib/http.js:568:28)
2021-05-18T05:42:15.372182+00:00 app[web.1]: at processTicksAndRejections (node:internal/process/task_queues:96:5) {
2021-05-18T05:42:15.372182+00:00 app[web.1]: remoteStacktrace: '#0 0x5630d5f6be89 <unknown>\n'
2021-05-18T05:42:15.372183+00:00 app[web.1]: }
2021-05-18T05:42:15.465529+00:00 heroku[web.1]: Process exited with status 1
2021-05-18T05:42:15.532468+00:00 heroku[web.1]: State changed from up to crashed
Nothing seems to fix the issue, I've added the required buildpacks, and have also checked all the versions. Also note that this code runs perfectly fine on my local machine. I saw a similar question where the user manually added the DevToolsActivePort file, but that doesn't seem to be possible as I can't ssh into the heroku server.
Thanks in advance.
You will need to pass in a flag to disable Chrome Devtools Sandbox, so it will no longer look for DevToolsActivePort. It is also recommended to disable-gpu with a headless webdriver:
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-gpu");

Nanoexpress server fails on Heroku & AWS - runs fine locally - cannot trace 'dest.on()' error

Relevant stack-trace below - from Heroku:
2020-04-28T17:49:11.997756+00:00 app[web.1]: Your app is listening on port 14385
2020-04-28T17:49:12.491486+00:00 heroku[web.1]: State changed from starting to up
2020-04-28T17:49:41.748150+00:00 heroku[web.1]: State changed from up to crashed
2020-04-28T17:49:41.649885+00:00 app[web.1]: _stream_readable.js:660
2020-04-28T17:49:41.649896+00:00 app[web.1]: dest.on('unpipe', onunpipe);
2020-04-28T17:49:41.649897+00:00 app[web.1]: ^
2020-04-28T17:49:41.649897+00:00 app[web.1]:
2020-04-28T17:49:41.649898+00:00 app[web.1]: TypeError: dest.on is not a function
2020-04-28T17:49:41.649899+00:00 app[web.1]: at ReadStream.Readable.pipe (_stream_readable.js:660:8)
2020-04-28T17:49:41.649900+00:00 app[web.1]: at SendStream.stream (/app/node_modules/send/index.js:798:10)
2020-04-28T17:49:41.649900+00:00 app[web.1]: at SendStream.send (/app/node_modules/send/index.js:707:8)
2020-04-28T17:49:41.649900+00:00 app[web.1]: at /app/node_modules/send/index.js:774:12
2020-04-28T17:49:41.649901+00:00 app[web.1]: at FSReqCallback.oncomplete (fs.js:172:5)
From AWS (EC2 using a Bitnami instance for NodeJS apps):
Your app is listening on port 8080
_stream_readable.js:666
dest.on('unpipe', onunpipe);
^
TypeError: dest.on is not a function
at ReadStream.Readable.pipe (_stream_readable.js:666:8)
at SendStream.stream (/opt/bitnami/apps/demo/htdocs/node_modules/send/index.js:798:10)
at SendStream.send (/opt/bitnami/apps/demo/htdocs/node_modules/send/index.js:707:8)
at /opt/bitnami/apps/coronavirus-demo/htdocs/node_modules/send/index.js:774:12
at FSReqCallback.oncomplete (fs.js:167:5)
error: Forever detected script exited with code: 1
error: Script restart attempt #1
I see that we seem to be dying on _stream_readable.js:666 where 'dest.on' isn't defined - and I'm way into the weeds of Node at this point - so I'm not sure what I'm looking for, but I find that we're defining this method further down in the file:
https://github.com/nodejs/node/blob/master/lib/_stream_readable.js:852 -
Is this as simple as we're evaluating this _stream_readable file top-down and we haven't defined on() as of line 666 and that's why it's failing?
But why would it work locally? The app runs fine with Nanoexpress server on a Macbook Pro - same package.json and lock files - no devDependencies that make any difference (the only devDependencies are like Mocha and Sinon and Chai for tests)
I've run the app locally with NODE_ENV=production and NPM_CONFIG_PRODUCTION=true (it's a React & Express [Nanoexpress] app) and it boots and I can get what I need running just fine.
It's only when I push to Heroku / AWS that I'm getting this failure. Feels like we're trying to use a function before it's defined...
nanoexpress author here.
nanoexpress works fine on Heroku on my projects, but on AWS did not test, but nanoexpress does not support Lambda/Serverless.
Please check first your code or try PRO version as now it's Free

Node.JS Redis connect EADDRNOTAVAIL error in Microsoft Azure Web App

I have a Node.js app deployed to a Microsoft Azure Web App and I can't seem to fix the following error:
Application has thrown an uncaught exception and is terminated:
> Error: Redis connection to
> <insertRedisHostNameHere> failed -
> connect EADDRNOTAVAIL
> at errnoException (net.js:670:11)
> at connect (net.js:548:19)
> at Socket.connect (net.js:613:5)
> at Object.<anonymous> (net.js:77:12)
> at RedisClient.create_stream (D:\home\site\wwwroot\node_modules\redis\index.js:218:31)
> at new RedisClient (D:\home\site\wwwroot\node_modules\redis\index.js:169:10)
> at Object.createClient (D:\home\site\wwwroot\node_modules\redis\index.js:906:12)
> at Object.<anonymous> (D:\home\site\wwwroot\server.js:8:20)
> at Module._compile (module.js:446:26)
> at Object..js (module.js:464:10)
The code that is causing this error is:
var redis = require('redis');
var client = redis.createClient(17397, '<hostname>', {enable_offline_queue: false});
client.auth('<password>', function(err){
});
client.on('connect', function(){
console.log('connected to redis');
});
I haven't been able to find a working solution, any help is greatly appreciated.
Additionally, I am able to run the same code on my localhost and local Redis cache without any problems at all.
Fixed it by updating the version of Node JS in package.json. (Refer to this question for more details: can't connect to DB - EADDRNOTAVAIL)

Sequelize giving TypeError

So I was casually devoloping a simple node.js app and it was working in my computer just fine.
I had installed heroku toolbelt and the app was running fine when I ran foreman start.
Deploying the app in heroku seems to be giving me some kind of error when conecting with postgres by using sequelize (I'm not even 100% sure that's the cause of the error, but almost). The app crashes and all I have is the heroku logs:
2014-01-05T11:07:39.850661+00:00 app[web.1]: Servidor escuchando al puerto: 25144
2014-01-05T11:07:39.911641+00:00 app[web.1]:
2014-01-05T11:07:39.912039+00:00 app[web.1]: timers.js:103
2014-01-05T11:07:39.912288+00:00 app[web.1]: if (!process.listeners('uncaughtException').length) throw e;
2014-01-05T11:07:39.913123+00:00 app[web.1]: ^
2014-01-05T11:07:39.915970+00:00 app[web.1]: at TransactionManager.getConnectorManager (/app/node_modules/sequelize/lib/transaction-manager.js:25:36)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at TransactionManager.query (/app/node_modules/sequelize/lib/transaction-manager.js:39:15)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at module.exports.Sequelize.query (/app/node_modules/sequelize/lib/sequelize.js:310:36)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/sequelize/lib/query-interface.js:901:40)
2014-01-05T11:07:39.915970+00:00 app[web.1]: TypeError: Cannot call method 'setTypeParser' of undefined
2014-01-05T11:07:39.915970+00:00 app[web.1]: at new module.exports.ConnectorManager (/app/node_modules/sequelize/lib/dialects/postgres/connector-manager.js:19:19)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at module.exports.CustomEventEmitter.run (/app/node_modules/sequelize/lib/emitters/custom-event-emitter.js:24:18)
2014-01-05T11:07:39.915970+00:00 app[web.1]: at Timer.list.ontimeout (timers.js:101:19)
2014-01-05T11:07:41.217303+00:00 heroku[web.1]: Process exited with status 1
2014-01-05T11:07:41.234281+00:00 heroku[web.1]: State changed from starting to crashed
The first line ("Servidor escuchando al puerto: XXXX") is actually part of app.js (the main .js file), it's the last few lines:
http.createServer(app).listen(app.get('port'), function(){
console.log('Servidor escuchando al puerto: ' + app.get('port'));
});
As I said before, it runs fine locally (executing foreman start correctly displays it on localhost) but I've had no luck on heroku.
Thanks for any insight and help =)
EDIT: I've managed to trace somewhat the error, seems there is a call to:
pg.types.setTypeParser(20, String)
somewhere in the sequelize module that throws the error since pg.types is undefined
I've checked by simply doing:
console.log(require('pg'));
And it indeed seems there is no field "types"
Is that the way it's meant to be? Am I missing something?
pg.types comes from a dependency of pg:
See package json here:
https://github.com/brianc/node-postgres/blob/master/package.json
This is the package here:
https://www.npmjs.org/package/pg-types
If you don't have it and you installed pg through npm, try removing pg and re-running npm install and see if there are any errors. It should download pg-types tool.
You can see where pg.types specifically is defined here:
https://github.com/brianc/node-postgres/blob/master/lib/index.js

Heroku Logs - open log referred to in error message

I'm deploying a node.js app to heroku (cedar stack)
I've set the NODE_ENV like this:
heroku config:add NODE_ENV=production
I then do:
git push heroku
However, after starting (i've got a console.log generating the first log entry) the app crashes.
I run:
heroku logs
and get the below error.
How can I open the /app/log/production.log that it's referring to?
app[web.1]: listening on port 32168 within production environment
app[web.1]:
app[web.1]: events.js:48
app[web.1]: throw arguments[1]; // Unhandled 'error' event
app[web.1]: ^
app[web.1]: Error: ENOENT, open '/app/log/production.log'
heroku[web.1]: Process exited with status 1
heroku[web.1]: State changed from starting to crashed
The error you're getting means that it's trying to open '/app/log/production.log' and is unable to do so. So find out where this logging is being attempted and disable or change it.
According to Heroku you should just be sending your application logs to STDOUT:
https://devcenter.heroku.com/articles/logging
So a console.log should be sufficient.

Resources