我在 node js 脚本中有一个函数,当我使用 node 命令行启动我的项目时它工作正常:
但是,当我从 Visual Studio 2015 运行项目时,我收到此错误:
调试器监听端口 5858 C:\nodejs\Apps\EMIApp\config\dal.js:69 response => { db.close(); ^^
语法错误:意外的令牌 =>
at exports.runInThisContext (vm.js:73:16) at Module._compile (module.js:443:25) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17) at Object.<anonymous> (C:\nodejs\Apps\EMIApp\Server.js:5:12) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) Press any key to continue...
有错误的代码示例是:
function connectDB (callback)
{
// Use connect method to connect to the Server
MongoClient.connect(url, function (err, db) {
if (err) //Return if any Error.
{
console.log('Unable to connect to the mongoDB server. Error:', err);
callback(err,null);
return;
}
//HURRAY!! We are connected. :)
console.log('Connection established to', url);
//Call the callback function provided & once done, close the connection from here. do not trust callback
callback(err,db).then(
response => { db.close(); **//This Line**
console.log("db closed");
},
reject => {
console.log("Some Error in Callback");
try
{
db.close();
}catch(e)
{
console.log(e);
}
}
);
});
}
我认为 Visual Studio 2015 无法解析此符号 =>。关于如何在 Visual Studio 2015 中完成这项工作的任何想法。