javascript - 如何将 RUN 操作绑定(bind)到 Cloud9 中正确的 NodeJS 版本?

标签 javascript node.js ecmascript-6 cloud9-ide cloud9

背景

我有一个非常简单的nodejs应用程序,它使用 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());

问题

当我单击index.js的运行按钮时(或者当您右键单击index.js然后选择“运行此文件”时)

我收到以下错误:

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)

但是,如果我在 bash 命令行中输入 node index.js 我会得到预期的输出:

I eat fruit colored yellow

此外,输入 node -v 输出:

v7.8.0

问题

我坚信运行选项没有选择正确的 Node 版本。 我该如何解决这个问题?

注释

为了更新 Node ,我使用了nvm install 7

最佳答案

回答

我对问题的识别是正确的。要修复它,需要运行以下命令:

nvm alias default 7

制作人员

Harutyun致敬++来寻找答案。

关于javascript - 如何将 RUN 操作绑定(bind)到 Cloud9 中正确的 NodeJS 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43089915/

相关文章:

javascript - 我们何时使用 preventDefault 方法重要吗?

javascript - 确定是创建新对象还是更新现有对象

node.js - 在 Mongoose 中将数组更新到文档中

android - Ubuntu 16/Cordova 6.4/Android : Could not resolve com. android.tools.build:gradle

node.js - 为什么Typescript编写的node_module会出现语法错误?

javascript - 如何将模型对象数组转换为以模型 ID 作为键的对象?

javascript - 找不到模块 'actions-on-google',正在使用 dialogflow

javascript - 当离线模式处于事件状态时,react-native-firebase 安全吗?

javascript - 双向、URL 友好的 Node.js slug 函数

javascript - 如何测试harmony/ES6/ECMAScript 6 JavaScript?