"[SyntaxError: Unexpected end of input]" Using Express for Node.js

The following works perfectly well for me:

app.get('/doi/meta/:doiName1/:doiName2', function(request, response) { var path = '/doi/json?doi='+request.params.doiName1+'/'+request.params.doiName2; // etc.

For instance, I can call:

curl -X GET http://localhost:1337/doi/meta/09.1010/9347426

and get the response I am expecting. (Note the name of the object I am querying has a slash.)

Because there is some potential variability in the object names, I have a need to alter the server so that I can structure my queries like this:

curl -X GET http://localhost:1337/doi/meta?doiName=09.1010/9347426

I have tried numerous approaches, but I invariably receive the following response:

[SyntaxError: Unexpected end of input]

which suggests to me that I am looking for the problem in the wrong place. However, I can change the server code back to the above and it works fine. My code currently looks like this:

app.get('/doi/meta', function(request, response) { //var path = '/doi/json?doi='+request.params.doiName1+'/'+request.params.doiName2; var args = url.parse(request.url, true).query; var path = 'doi/json?doi='+args['doiName']; console.log('path is '+path); // etc.

The console.log statement is never reached. What is the issue that is causing this Unexpected End of Input error?

-------------Problems Reply------------

A SyntaxError: Unexpected end of input error typically means either you are missing a closing parenthesis, brace, bracket, or similar character somewhere in your code or you are trying to JSON.parse() a string that is missing such characters.

Run your code/JSON string through a javascript linter (e.g. jshint) to find syntax errors.

What was happening was that several hundred lines above in the same file there was another GET listener:

app.get('/doi/:user', function(request, response) {

This block was catching calls like:


and going to look for a user named meta. Naturally, this phenomenon did not occur when I structured the GET block like this:

app.get('/doi/meta/:doiName1/:doiName2', function(request, response) {

I am going to address this issue by "deepening" the first listener above to something like...

app.get('/doi/user/:user', function(request, response) {

Another lesson learned is to group similar URL calls together in the same file.

Thanks for the responses.

Category:node.js Views:1 Time:2014-10-26

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.164 (s). 11 q(s)