Error: failed to connect to [localhost:27017] when running MEAN app on HEROKU - node.js

I'm writing my second MEAN app. The first one was build aggregating the components by hand (I was not aware of MEAN) and hosting it at HEROKU; I attempted to use MONGOOSE but gave up due to problems connecting with the database at HEROKU - it worked fine on my MAC. This time around it works on my MAC but I'm still having connection problems; I do not want to jettison MONGOOSE. At this point all I have is the vanilla MEAN app built off its zip file, the zip file downloaded from the MEAN GitHUB repository. See below for the logs I get from HEROKU:
2013-09-10T01:33:28.045816+00:00 heroku[web.1]: Starting process with command `grunt`
2013-09-10T01:33:29.526090+00:00 app[web.1]: Running "jshint:all" (jshint) task
2013-09-10T01:33:29.567534+00:00 app[web.1]: >> 1 file lint free.
2013-09-10T01:33:29.568809+00:00 app[web.1]:
2013-09-10T01:33:29.568809+00:00 app[web.1]: Running "compass:dist" (compass) task
2013-09-10T01:33:29.573055+00:00 app[web.1]: Warning: You need to have Ruby and Compass installed and in your system PATH for this task to work. More info: https://github.com/gruntjs/grunt-contrib-compass Used --force, continuing.
2013-09-10T01:33:29.574527+00:00 app[web.1]: Warning: Cannot read property 'stdout' of undefined Used --force, continuing.
2013-09-10T01:33:29.574641+00:00 app[web.1]:
2013-09-10T01:33:29.575774+00:00 app[web.1]: Warning: You need to have Ruby and Compass installed and in your system PATH for this task to work. More info: https://github.com/gruntjs/grunt-contrib-compass Used --force, continuing.
2013-09-10T01:33:29.574641+00:00 app[web.1]: Running "compass:dev" (compass) task
2013-09-10T01:33:29.576128+00:00 app[web.1]: Running "concurrent:target" (concurrent) task
2013-09-10T01:33:29.576043+00:00 app[web.1]:
2013-09-10T01:33:30.414023+00:00 app[web.1]: Running "nodemon:dev" (nodemon) task
2013-09-10T01:33:30.511082+00:00 app[web.1]: 10 Sep 01:33:30 - [nodemon] v0.7.10
2013-09-10T01:33:30.511537+00:00 app[web.1]: 10 Sep 01:33:30 - [nodemon] to restart at any time, enter `rs`
2013-09-10T01:33:30.511664+00:00 app[web.1]: 10 Sep 01:33:30 - [nodemon] watching: /app/config
2013-09-10T01:33:30.511664+00:00 app[web.1]: 10 Sep 01:33:30 - [nodemon] watching: /app/app
2013-09-10T01:33:30.536018+00:00 app[web.1]: 10 Sep 01:33:30 - [nodemon] Unable to write to temp directory. If you experience problems with file reloading, ensure /tmp is writable.
2013-09-10T01:33:30.550590+00:00 app[web.1]: debugger listening on port 5858
2013-09-10T01:33:30.578354+00:00 app[web.1]: Running "watch" task
2013-09-10T01:33:30.624330+00:00 app[web.1]: Waiting...10 Sep 01:33:30 - [nodemon] reading ignore list
2013-09-10T01:33:31.152639+00:00 app[web.1]: throw er; // Unhandled 'error' event
2013-09-10T01:33:31.154862+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
2013-09-10T01:33:31.148967+00:00 app[web.1]: Express app started on port 3000
2013-09-10T01:33:31.152143+00:00 app[web.1]:
2013-09-10T01:33:31.152401+00:00 app[web.1]: events.js:72
2013-09-10T01:33:31.154862+00:00 app[web.1]: Error: failed to connect to [localhost:27017]
2013-09-10T01:33:31.154862+00:00 app[web.1]: at null.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
2013-09-10T01:33:31.154862+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
2013-09-10T01:33:31.154862+00:00 app[web.1]: at Socket.EventEmitter.emit (events.js:95:17)
2013-09-10T01:33:31.154862+00:00 app[web.1]: at process._tickCallback (node.js:415:13)
Any comments of suggestions would be much welcome. Thanks in advance.

You need to host MongoDB somewhere. There are a number of MongoDB hosting services, MongoHQ and MongoLab the most popular. I have used MongoHQ with good results although I must admit I haven't stressed my system. You can sign up for the free trial (I think you get 512MB), once you have done that, replace your connection string with (you will get all the details when signing up):
'mongodb://username:password#domain:port/dbName'

Related

nodemon throwing unhandled error event

I am trying to run nodemon on my local pc.
Even if i just run the command without parameters i get the following error:
events.js:182
throw er; // Unhandled 'error' event
^
Error: spawn cmd ENOENT
at _errnoException (util.js:1019:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
Turning on Verbose mode gives additional info along wiht this error:
[nodemon] Looking in package.json for nodemonConfig
[nodemon] 1.12.1
[nodemon] reading config C:\nodeprojects\myproject\package.json
[nodemon] to restart at any time, enter `rs`
[nodemon] ignoring: .git .nyc_output .sass-cache bower_components coverage C:\nodeprojects\myproject\node_modules/**/*
[nodemon] watching: *.*
[nodemon] watching extensions: js,json
[nodemon] starting `node app.js`
[nodemon] child pid: undefined
[nodemon] exiting
events.js:182
throw er; // Unhandled 'error' event
^
(Note - paths in above error altered to remove my username)
I have tried the basics, restarting my pc, checking if another app is using port 3000 (i dont think it is).
Any help or advice would be appreciated
Nodemon simply starts command "node app.js", if start node ok, it'll track files changes and restart node process.
Your error seems to cause by lack of nodejs configurations.
Try to check node program directory path is included in PATH variable or not.
In the windows pc, there're steps:
Find node install folder, commonly in C:\Program Files\nodejs or C:\Windows\System32\
Check this folder path in PATH variable value.

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;

Node.js + socket.io runs locally with foreman but crashes on heroku

I get the following error when running on heroku:
4-07-26T22:24:01.691178+00:00 heroku[web.1]: State changed from starting to crashed
2014-07-26T22:24:01.692242+00:00 heroku[web.1]: State changed from crashed to starting
2014-07-26T22:24:04.483585+00:00 app[web.1]:
26)
...
2014-07-26T22:24:04.484066+00:00 app[web.1]: ^
2014-07-26T22:24:04.485813+00:00 app[web.1]: at Module.load (module.js:356:32)
2014-07-26T22:24:04.484057+00:00 app[web.1]: throw err;
2014-07-26T22:24:04.485806+00:00 app[web.1]: at require (module.js:380:17)
2014-07-26T22:24:04.483677+00:00 app[web.1]: module.js:340
2014-07-26T22:24:04.485808+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/socket.io/node_modules/socket.io-parser/node_modules/emitter/index.js:6:13)
If I use, "heroku labs:enable websockets", I get "No such feature: websockets"
Problem
Heroku can't find an object in your ../emitter/index.js. Some folders of the socket.io modules are "gitignored". (Why?)
It looks like websockets are no heroku:labs feature anymore and are enabled by default. I ran the socket.io chat example without enabling the labs feature.
Quick Solution
git add -A --force | then commit and deploy

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

Resources