Parse-server: events.js:141 throw er; // Unhandled 'error' event in index.js

Created on 19 Feb 2016  路  18Comments  路  Source: parse-community/parse-server

DATABASE_URI not specified, falling back to localhost.
events.js:141
throw er; // Unhandled 'error' event
^

Error: listen EADDRINUSE :::1337
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at Server._listen2 (net.js:1236:14)
at listen (net.js:1272:10)
at Server.listen (net.js:1368:5)
at Function.app.listen (/Users/Documents/workspaceParse/parse-server-example/node_modules/express/lib/application.js:532:24)
at Object. (/Users/Documents/workspaceParse/parse-server-example/index.js:36:5)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v4.3.1
npm ERR! npm v2.14.12
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: node index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'node index.js'.
npm ERR! This is most likely a problem with the parse-server-example package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get their info via:
npm ERR! npm owner ls parse-server-example
npm ERR! There is likely additional logging output above.

Most helpful comment

This is because you are already running the parse server somewhere else. See #510

All 18 comments

This is because you are already running the parse server somewhere else. See #510

@drew-gross Thank you, That solved the problem. But I am still getting this error : DATABASE_URI not specified, falling back to localhost.
parse-server-example running on port 1337.

This is a section from index.js where I define all these values
var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;

if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
databaseURI: databaseUri || mongodb://myappDBUserName:[email protected]:59165/parse_myApp',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAPPID************',
masterKey: process.env.MASTER_KEY || 'myAPPMasterKey*************'
});
Should I be defining process.env.DATABASE_URI || process.env.MONGOLAB_URI? and where?

You can specify the databaseUri in your parse server configuration. See the getting started section of the readme.

@drew-gross
Note: I am using the parse-server-example not parse-server code. I was thinking to replace the main.js file of parse-server-example and run it as server.

index.js file of parse-server-example is pretty much same as the readme section of parse-server except few things including this below section

`var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;

if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
`
So may be I can just remove this section?

Few questions : Should i not be using parse-server-example and using parse-server?
If I start using parse-server then I am not sure how to setup express.
Am I right in simply replacing main.js of parse-server-example with my main.js and use it?

Using parse-server-example is a good idea, we recommend that. Replacing (or editing) main.js from parse-server-example is definitely the way to go. You can indeed remove that section. As long as you specify your database uri, you don't have to do it in the same way parse-server-example does it.

@drew-gross Thank you. That help in understanding.

Few more questions :

  1. I see 2 main.js files in parse-server-example one is in the path
    /parse-server-example/node_modules/parse-server/src/cloud
    another in /parse-server-example/cloud. // This one is the one which seems to work.
    why there are 2 files? Both have different code. Can you please tell which one is for what purpose?
  2. I am able to run the server but I am getting below error on a query lookup.
    error: unauthorized
    here is the code :
    var userNameQuery = new Query(Users);
    userNameQuery.equalTo("userPhoneNumber", formatedReceiverNumber);// this line is returning error with

curl -X POST
-H "X-Parse-Application-Id: myAPPId*******"
-H "Content-Type: application/json"
-d '{"senderName":"Test","senderNumber":16664440000,"receiverName":"TestR","receiverNumber":16664441111,"appMessage":"TestMSG","Date":"","Time":"","DateTime":"","Status":"A","TimeZone":"PST"}'
http://localhost:1337/parse/functions/SaveNewMSG

Did you set your server url in your configuration?

@drew-gross i dont have any server url in index.js. I am assuming thats the config file you are talking about. What server url should i be adding?
I have
'var databaseUri =' 'mongodb://myappDBUserName:[email protected]:59165/parse_myApp';

I dont understand why defining a server will have to do anything to with this error ? The call is able to run the code but throws unauthorized on equalTo query.

--Also below is what I am doing

var userNameQuery = new Query(Users);
userNameQuery.equalTo("userPhoneNumber", formatedReceiverNumber);
// next block goes to error.
userNameQuery.find(
{ success: function(results) {// I do something here},
error: function(error) { callbacks.error("Error finding userName. Error:" + error.message); }
});

The server needs to know it's own URL for a few reasons, including initializing the SDK, and generating links for email verifications. If you don't provide one, the SDK will default to api.parse.com which is why you see the unauthorized error. The server URL goes in the server configuration, check out the readme for more details.

@drew-gross Thank you so much. The server has been up and running.

Question : How can i see the logs when i make requests from my app. If I run curl commands I can see the log printing in console but when I make requests from my app nothing prints on the same console.

You can use VERBOSE=1 environment variable to log to the console, or add a LoggerAdapter such as FileLoggerAdapter to log to a file. If you want something fancier, you can implement your own LoggerAdapter that, say, logs to an external service.

@drew-gross Did you mean setting up process.env.VERBOSE for node.js?

is this something which I can look at for FileLoggerAdapter?

Yes, exactly.

@drew-gross adding export VERBOSE=1 before running npm start doesn't log anything.

Just to add clarity. I am trying to print console logs from cloud code.
EX: console.log("Error finding installationId" + error.message);

@drew-gross apart from not being able to see console. I am also getting this error:
com.parse.ParseRequest$ParseRequestException: bad json response

search on google shows it might be due to dependencies but I have everything in my dependencies
Below is my dependencies
dependencies {
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile files('libs/Parse-1.13.0.jar')
compile 'com.parse.bolts:bolts-android:1.+'
compile files('libs/simmetrics_jar_v1_6_2_d07_02_07.jar')
compile('com.digits.sdk.android:digits:1.9.3@aar') {
transitive = true;
}

@drew-gross can you please help ? This issue seems to be back with 1.13.0 version.

Here is someone else reported this earlier

If I move to 1.12.0 version I get error initializing parse in below code saying can not resolve method server(java.lang.string)
Parse.initialize(new Parse.Configuration.Builder(context)
.applicationId("MyAPPID*******")
.clientKey(null)
.server("http://10.0.2.2:1337/parse")
.build()
);

The bad json response issue sounds like a Parse Server issue, but I need more info to help. Can you open a new issue that include the request you are making to the Server that receives the bad json response? If you are not seeing anything being logged on the Parse Server, that probably means that the request is failing before it gets to the Server.

@drew-gross I have created a new issue here. What other Information I can provide ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kilabyte picture kilabyte  路  4Comments

carjo422 picture carjo422  路  3Comments

pulse1989 picture pulse1989  路  3Comments

ViolentCrumble picture ViolentCrumble  路  3Comments

yuzeh picture yuzeh  路  3Comments