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

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

Related

NODEJS Error when try to start a prod enviroment

hope somebody can help me, Im pretty new dealing with prod enviroment, Im trying to deploy my nodejs backend on aws ec2 linux instance. Using pm2 to run the enviroment but after y use pm2 start ecosystem.config.js --env production command and I log the output I've got this logs:
at process.emit (events.js:327:22)
at emit (internal/child_process.js:876:12)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Error: bind EACCES null:80
at listenOnMasterHandle (net.js:1380:18)
at rr (internal/cluster/child.js:132:12)
at Worker.<anonymous> (internal/cluster/child.js:99:7)
at process.onInternalMessage (internal/cluster/utils.js:47:8)
at process.emit (events.js:327:22)
at emit (internal/child_process.js:876:12)
at processTicksAndRejections (internal/process/task_queues.js:85:21)

METEOR_SETTINGS is not valid json error when deploying meteor app to heroku

As the title says, I am getting that error when deploying my meteor app to heroku. I have already validated my settings.json file with JSONlint and have searched for any possible fix but I have not come across any which work. My error logs are as shown below. Could anyone tell me what might be wrong?
2017-09-03T11:18:31.226632+00:00 heroku[web.1]: Starting process with command `.meteor/heroku_build/bin/node $NODEJS_PARAMS .meteor/heroku_build/app/main.js`
2017-09-03T11:18:33.344368+00:00 app[web.1]: /app/.meteor/heroku_build/app/programs/server/boot.js:391
2017-09-03T11:18:33.344382+00:00 app[web.1]: }).run();
2017-09-03T11:18:33.344383+00:00 app[web.1]: ^
2017-09-03T11:18:33.344384+00:00 app[web.1]:
2017-09-03T11:18:33.344385+00:00 app[web.1]: Error: METEOR_SETTINGS are not valid JSON: $(cat settings.json)
2017-09-03T11:18:33.344385+00:00 app[web.1]: at packages/meteor.js:59:11
2017-09-03T11:18:33.344386+00:00 app[web.1]: at packages/meteor.js:80:4
2017-09-03T11:18:33.344387+00:00 app[web.1]: at packages/meteor.js:1380:3
2017-09-03T11:18:33.344388+00:00 app[web.1]: at /app/.meteor/heroku_build/app/programs/server/boot.js:338:34
2017-09-03T11:18:33.344388+00:00 app[web.1]: at Array.forEach (native)
2017-09-03T11:18:33.344389+00:00 app[web.1]: at Function._.each._.forEach (/app/.meteor/heroku_build/app/programs/server/node_modules/underscore/underscore.js:79:11)
2017-09-03T11:18:33.344390+00:00 app[web.1]: at /app/.meteor/heroku_build/app/programs/server/boot.js:158:5
2017-09-03T11:18:33.344391+00:00 app[web.1]: at /app/.meteor/heroku_build/app/programs/server/boot.js:387:5
2017-09-03T11:18:33.344392+00:00 app[web.1]: at Function.run (/app/.meteor/heroku_build/app/programs/server/profile.js:510:12)
2017-09-03T11:18:33.344392+00:00 app[web.1]: at /app/.meteor/heroku_build/app/programs/server/boot.js:386:11
2017-09-03T11:18:33.415049+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-03T11:18:33.400865+00:00 heroku[web.1]: Process exited with status 1
Your problem is with this command:
heroku config:add METEOR_SETTINGS="$(cat settings.json)"
You see, on Windows, the $(cat settings.json) means just text, but on Mac/*nix that means "get content of settings.json file".
I'd recommend to use git bash cli to run this command there. Link to Git for Windows (with git bash cli): https://git-for-windows.github.io/
In windows, you can compress the setting.json file in notepad++ (Plugins->JSON viewer -> Compress JSON) then run the below command by coping the compressed json content as follow
SET METEOR_SETTINGS={"configuration":{"images-folder":"","internal-folder":"","demo-mode":false},"sets-of-classes":[{"name":"Cityscapes","objects":[{"label":"VOID","color":"#CFCFCF"},{"label":"Road","color":"#804080","icon":"Road"},{"label":"Sidewalk","........
now you can run the usual command

Sails.js app fails to deploy on heroku

My sails.js application works fine on localhost but fails on heroku.
I have below settings in my production.js
port: process.env.PORT || 1337,
environment: process.env.NODE_ENV || 'development',
Still getting below messages and deployment fails;
2015-02-10T03:54:55.089482+00:00 app[web.1]: Tue, 10 Feb 2015 03:54:55 GMT i18n:debug read /app/config/locales/de.json for locale: de
2015-02-10T03:54:55.089220+00:00 app[web.1]: Tue, 10 Feb 2015 03:54:55 GMT i18n:debug will write to /app/config/locales/fr.json
2015-02-10T03:54:55.089261+00:00 app[web.1]: Tue, 10 Feb 2015 03:54:55 GMT i18n:debug read /app/config/locales/fr.json for locale: fr
2015-02-10T03:54:55.089453+00:00 app[web.1]: Tue, 10 Feb 2015 03:54:55 GMT i18n:debug will write to /app/config/locales/de.json
2015-02-10T03:54:55.138917+00:00 app[web.1]: designed for a production environment, as it will leak
2015-02-10T03:54:55.138919+00:00 app[web.1]: memory, and will not scale past a single process.
2015-02-10T03:54:55.393772+00:00 app[web.1]: http hook loaded successfully.
2015-02-10T03:54:55.396900+00:00 app[web.1]: sockets hook loaded successfully.
2015-02-10T03:54:55.397665+00:00 app[web.1]: Located 0 user hook(s)...
2015-02-10T03:54:55.413955+00:00 app[web.1]: Setting default Express view engine to jade...
2015-02-10T03:54:55.415525+00:00 app[web.1]: Loading adapter ( sails-mongo ) for user from `node_modules` directory...
2015-02-10T03:54:55.394180+00:00 app[web.1]: Configuring socket (ws://) server...
2015-02-10T03:54:55.397318+00:00 app[web.1]: Loading user hooks...
2015-02-10T03:54:55.397942+00:00 app[web.1]: views hook loaded successfully.
2015-02-10T03:54:55.414283+00:00 app[web.1]: Initialized 0 user hook(s)...
2015-02-10T03:54:55.414314+00:00 app[web.1]: userhooks hook loaded successfully.
2015-02-10T03:54:55.415058+00:00 app[web.1]: Forcing Waterline to use `migrate: "safe" strategy (since this is production)
2015-02-10T03:54:55.606849+00:00 app[web.1]: Starting ORM...
2015-02-10T03:54:55.771204+00:00 app[web.1]: pubsub hook loaded successfully.
2015-02-10T03:54:55.931003+00:00 app[web.1]: Grunt :: >> Local Npm module "grunt-simple-mocha" not found. Is it installed?
2015-02-10T03:54:55.769438+00:00 app[web.1]: orm hook loaded successfully.
2015-02-10T03:54:56.159039+00:00 app[web.1]: Grunt :: Running "clean:dev" (clean) task
2015-02-10T03:54:56.180324+00:00 app[web.1]: Grunt :: >> Destination not written because compiled files were empty.
2015-02-10T03:54:56.184386+00:00 app[web.1]: Grunt :: Running "copy:dev" (copy) task
2015-02-10T03:54:56.180479+00:00 app[web.1]: Grunt :: Running "less:dev" (less) task
2015-02-10T03:54:56.162834+00:00 app[web.1]: Grunt :: Running "jst:dev" (jst) task
2015-02-10T03:54:56.729594+00:00 app[web.1]: Grunt :: , copied 542 files
2015-02-10T03:54:56.729493+00:00 app[web.1]: Grunt :: Created 4 directories
2015-02-10T03:54:56.730009+00:00 app[web.1]: Grunt :: Running "coffee:dev" (coffee) task
2015-02-10T03:54:56.856265+00:00 app[web.1]: Grunt :: Running "concat:js" (concat) task
2015-02-10T03:54:57.062061+00:00 app[web.1]: Grunt :: File ".tmp/public/concat/production.js" created.
2015-02-10T03:54:57.063749+00:00 app[web.1]: Grunt :: File ".tmp/public/concat/production.css" created.
2015-02-10T03:54:57.064113+00:00 app[web.1]: Grunt :: Running "uglify:dist" (uglify) task
2015-02-10T03:54:57.062590+00:00 app[web.1]: Grunt :: Running "concat:css" (concat) task
2015-02-10T03:55:53.360980+00:00 heroku[web.1]: Stopping process with SIGKILL
2015-02-10T03:55:53.360980+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2015-02-10T03:55:54.179225+00:00 heroku[web.1]: Process exited with status 137
2015-02-10T03:55:54.193814+00:00 heroku[web.1]: State changed from starting to crashed
Please advise, thanks.
You app is running in production mode. I can tell this because of Forcing Waterline to use `migrate: "safe" strategy (since this is production) and the concat/uglify tasks are running.
It is possible that this process (concat/uglify) is busting the allocated memory. I have seen this when deploying on small heroku instances with a lot of js/css to process. You might want to try the https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt to run grunt on deploy instead of launch.
See http://blog.mdarveau.com/2014/10/20/deploying-to-heroku for my experience on deploying a sails app to heroku.
The following part from the logs is weird though:
2015-02-10T03:54:55.138917+00:00 app[web.1]: designed for a production environment, as it will leak
2015-02-10T03:54:55.138919+00:00 app[web.1]: memory, and will not scale past a single process.
Set migrate: 'alter' in config/models.js
quick (temporary) solution is just remove production flag
delete process.env.NODE_ENV;

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