简体   繁体   English

console.log(util.format运行错误

[英]running error with console.log(util.format

First I have to say, I'm new to node.js. 首先,我必须说,我是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 . 我已经通过npm安装了必需的包search-google-geocodecsv-parserfsutilasync

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;
    });
});

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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM