javascript - 在服务器上为 socket.io 运行 index.js 时出错

标签 javascript node.js swift amazon-web-services socket.io

一段时间以来,我一直在尝试让我的 index.js 脚本在我的 AWS EC2 服务器上为我的聊天应用程序运行。我已将 Node 更新到最新版本 (9.4.0) 和 NPM。

当我尝试使用以下方式运行脚本时:

sudo node index.js 

我收到以下错误:

SyntaxError: Use of const in strict mode.

在互联网上阅读我设法通过使用以下行运行脚本来规避这一点:

sudo node --harmony index.js

但是现在我收到以下错误并且无法解决它: (指向错误位置的小克拉就在下面等号后面的第一个右括号下面)

const native = (() => { ^

SyntaxError: Unexpected reserved word
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/var/www/html/example/node/node_modules/ws/index.js:9:19)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

我根本不是 Node 方面的专家,也没有做很多后端编程。只是试图让索引文件运行。

最佳答案

const 在 Node 中得到支持已有一段时间了。您确定您使用的是最新版本的 Node 吗?你能检查 node -v 的返回值吗?

关于javascript - 在服务器上为 socket.io 运行 index.js 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48552794/

相关文章:

javascript - 如何在 node.js + socket.io 中创建自定义客户端事件

swift - 为什么timer失效后还继续执行?

ios - 如何在Swift中同时添加Button+ScrollView?

ios - 如何在 View Controller 之间滑动?

javascript - 即使传入并请求全局对象,全局对象在自定义模块中也不可用

javascript - jQuery:从对象数据创建数组

javascript - isAuthenticated() 函数无法正常工作 Node.js Passport

javascript - 未为使用 Firefox 的 Knockout 单击绑定(bind)定义事件参数

javascript - 何时在 jQuery AJAX 中执行 $.ajax 或 $.get 或 $.post

javascript - Angular 跨域请求 CORS 失败,但 Node http.get() 返回成功