0

First I have to say, I'm new to node.js.

One of my mate helped me with the piece of code below.

I've installed the required packages search-google-geocode , csv-parser , fs , util and async through npm.

Yet, when I'm running it.

I've got this error

console.log(util.format("  Area %s", preciseLoc.area);
                ^^^^^^^
SyntaxError: Unexpected identifier
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

I thought first it was due to a missing semi-colon but it is not the case.

Does it sound familiar? If yes, do you have any ideas on how to fix the issue?

The piece of code

var geocoder = require('search-google-geocode');
var csv = require('csv-parser');
var fs = require('fs');
var util = require('util');
var async = require('async');

var options = {
    language: 'fr'
};

var locs = [];

var csvReader = fs.createReadStream('locs2.csv').pipe(csv());

var geoResult = function(err, result) {
}

csvReader.on('data', function(data) {
    locs.push(data);
});

var rowCount = 1;
csvReader.on('end', function() {
    console.log(locs.length + " rows read from CSV");
    async.eachSeries(locs, function(loc, cb) {
        console.log("\nLooking up row " + rowCount + ": " + loc.lat + "," + loc.lon);
        rowCount++;
        geocoder.reverseGeocode(loc.lat, loc.lon, function(err, result) {
            if (err) {
                console.log(err);
            } else {
                var preciseLoc = result[0];
                console.log(util.format("Reverse geocode: %s, %s", preciseLoc.latitude, preciseLoc.longitude)
                console.log(util.format("  Area %s", preciseLoc.area));
                console.log(util.format("  Zip %s", preciseLoc.zipcode));
            }

            cb();
        } , options);
    },

    function(err) {
        return null;
    });
});

1 Answer 1

1

It looks to me like this line:

console.log(util.format("Reverse geocode: %s, %s", preciseLoc.latitude, preciseLoc.longitude)

is missing a closing bracket and should probably be changed to:

console.log(util.format("Reverse geocode: %s, %s", preciseLoc.latitude, preciseLoc.longitude));
Sign up to request clarification or add additional context in comments.

1 Comment

Damn. Thanks Ben. It was that -_-

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.