Javascript 控制台中的Node.js调试消息,很奇怪

Javascript 控制台中的Node.js调试消息,很奇怪,javascript,node.js,Javascript,Node.js,我的代码: var prompt = require('sync-prompt').prompt; var input = prompt('What is it you are after? '); var mkdirp = require('mkdirp'); var fs = require('fs'); var url = require('url'); var http = require('http'); var exec = require('child_process').exec

我的代码:

var prompt = require('sync-prompt').prompt;
var input = prompt('What is it you are after? ');
var mkdirp = require('mkdirp');
var fs = require('fs');
var url = require('url');
var http = require('http');
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var unzip = require('unzip');
console.log('Okay, we will do our best to find ' + input + ', ' + ' ' + 'hold on.');
var mysql = require('mysql');
var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root', //just using root for my personal testing.
    password: 'root',
    database: 'Sonic'
});
connection.query('SELECT *  FROM Sonic_URL WHERE Name="' + input + '"', function(err, rows, fields) {
    if (err) throw err;
    var Name = (fields[0].Uname);
    if (Name === input) {
        console.log("Found it! Just getting the download!");
    }
    }
    //download progress bar
    var ProgressBar = require('progress');
    var bar = new ProgressBar(':bar', {
        total: 10
    });
    var timer = setInterval(function() {
        bar.tick();
        if (bar.complete) {
            console.log('\ncomplete\n');
            clearInterval(timer);
        }
    }, 100);
    //Building the download//
    var spawn = require('child_process').spawn;
    //Location of download. 
    var DOWNLOAD_DIR = './Sonic-Downloads';
    //Making sure the Dir exists
    var mkdir = 'mkdir ' + DOWNLOAD_DIR;
    var child = exec(mkdir, function(err, stdout, stderr) {
        // if (err) console.log('Awww snap! d') Ingnore this
        download_file_httpget((rows[0].Address));
    });
}
// Function to download file using HTTP.get
var download_file_httpget = function(sqlres) {
    var options = {
        host: url.parse(sqlres).host,
        //port: ,
        path: url.parse(sqlres).pathname
    };
    var sqlres = url.parse(sqlres).pathname;
    var file = fs.createWriteStream(DOWNLOAD_DIR + sqlres);
    http.get(options, function(res) {
        res.on('data', function(data) {
            file.write(data);
        }).on('end', function() {
            file.end();
            console.log('Succsesfully downloaded ' +
                namematch);
            // Other things that need to be closed go here 
            process.exit();
        });
    });
};
});

//shut down code
process.on('SIGINT', function() {
    console.log(
        "\nGoodbye!a!"
    );
    // some other closing procedures go here
    process.exit();
})
当我用node命令运行这段代码时,我得到了这个结果

SyntaxError: missing ) after argument list
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
SyntaxError: Unexpected token var
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
照上面说的做了之后,我得到了这个

SyntaxError: missing ) after argument list
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
SyntaxError: Unexpected token var
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
不知道为什么要这样做,我已经检查过了,以确保所有,{},[],()等匹配,关闭等,任何帮助都将不胜感激

if (Name === input) {
    console.log("Found it! Just getting the download!");
}
}
拆下一个支架

connection.query('SELECT *  FROM Sonic_URL WHERE Name="' + input + '"',     function(err, rows, fields) {
if (err) throw err;
var Name = (fields[0].Uname);
if (Name === input) {
    console.log("Found it! Just getting the download!");
}

//download progress bar
var ProgressBar = require('progress');
var bar = new ProgressBar(':bar', {
total: 10 
});
var timer = setInterval(function() {
bar.tick();
if (bar.complete) {
    console.log('\ncomplete\n');
    clearInterval(timer);
} 
}, 100);
//Building the download//
var spawn = require('child_process').spawn;
//Location of download. 
var DOWNLOAD_DIR = './Sonic-Downloads';
//Making sure the Dir exists
var mkdir = 'mkdir ' + DOWNLOAD_DIR;
var child = exec(mkdir, function(err, stdout, stderr) {
 // if (err) console.log('Awww snap! d') Ingnore this
 download_file_httpget((rows[0].Address));
});  
})

如果你正确缩进代码,错误是很明显的。在我把它放在堆栈溢出上之前,缩进都很好,缩进被抹掉了。如下所述,似乎有几个额外的卷曲块等。我将为你缩进。谢谢!这就解决了问题。