I have a very sinmple nodejs app that uses the Object Destructur Operator of ECMA6
"use strict";
function bananas(){
return {
type: "fruit",
color: "yellow"
};
}
function eat(){
var {
type,
color
} = bananas();
return `I eat ${type} colored ${color}`;
}
console.log(eat());
When I click the run button of index.js (or when you go right-click index.js and then select "Run this file")
I get the following error:
Debugger listening on [::]:15454
/home/ubuntu/workspace/server/index.js:16
var {
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.runMain [as _onTimeout] (module.js:441:10)
at Timer.listOnTimeout (timers.js:92:15)
However, if I type in the bash command line node index.js
I get the expected output:
I eat fruit colored yellow
Furthermore, typing node -v
outputs:
v7.8.0
It is my strong believe that the run option is not picking up the correct version of node. How can I fix that?
To update node I used nvm install 7
.
My identification of the issue was correct. To fix it one needs to run the following command:
nvm alias default 7
Kudos++ to Harutyun for the answer.