Visual Studio 2015 中的 Nodejs 代码会抛出错误,但可以从节点命令行运行。意外的令牌 =>
Nodejs Code in Visual Studio 2015 throws error but works from node command line. Unexpected token =>
我在 node js 脚本中有一个函数,当我使用 node 命令行启动我的项目时它工作正常:
然而,当我 运行 2015 年 visual studio 的项目时,我得到了这个错误:
Debugger listening on port 5858 C:\nodejs\Apps\EMIApp\config\dal.js:69
response => { db.close();
^^
SyntaxError: Unexpected token =>
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 年完成这项工作的任何想法。
所以我终于找到了问题。
Visual Studio 2015 安装节点版本 v0.12.2 在 C:\Program Files (x86)\nodejs.
& 我在 c:\nodejs 安装了另一个节点(分别在 vs 2015 安装之前),版本为 v4.4.3.
在项目的属性页中,我把node.exe的路径改成指向最新的
我在 node js 脚本中有一个函数,当我使用 node 命令行启动我的项目时它工作正常:
然而,当我 运行 2015 年 visual studio 的项目时,我得到了这个错误:
Debugger listening on port 5858 C:\nodejs\Apps\EMIApp\config\dal.js:69 response => { db.close(); ^^
SyntaxError: Unexpected token =>
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 年完成这项工作的任何想法。
所以我终于找到了问题。
Visual Studio 2015 安装节点版本 v0.12.2 在 C:\Program Files (x86)\nodejs.
& 我在 c:\nodejs 安装了另一个节点(分别在 vs 2015 安装之前),版本为 v4.4.3.
在项目的属性页中,我把node.exe的路径改成指向最新的