I have a function in node js script which works fine when I am using node command line to start my project:
However when I run the project from visual studio 2015, I get this Error :
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...
The code sample which has error is :
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);
}
}
);
});
}
I think Visual Studio 2015 is unable to resolve this symbol => . Any ideas on how to make this work in visual studio 2015.
So I finally managed to find the issue.
Visual Studio 2015 installed Node Version v0.12.2 at C:\Program Files (x86)\nodejs.
& I had another node installed (separately before vs 2015 installation ) at c:\nodejs Which was version v4.4.3.
In the properties page of the project, I changed the path of node.exe to point to the latest one.