安装 wscat 简单

npm install -g wscat

$ wscat -c ws://echo.websocket.org
Connected (press CTRL+C to quit)
> hi there
< hi there
> are you a happy parrot?
< are you a happy parrot?

据说可用了,但是环境报错了

wscat -h                                                                                                                                  
/usr/lib/node_modules/wscat/node_modules/ws/lib/websocket.js:354
...options
^^^

SyntaxError: Unexpected token ...
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/lib/node_modules/wscat/node_modules/ws/index.js:3:19)

网上没有说明关于  wscat 安装报错的问题。

有幸发现  这是 nodejs 语法不兼容问题。也有帖子介绍,系统的yum源安装nodejs版本太低。如果你的系统版本比较低,gcc库版本低,编译安装的时候有可能不成功,下面是yum安装的步骤

查看一下版本 确实低

升级 nodejs 版本即可解决

curl --silent --location https://rpm.nodesource.com/setup_12.x | bash 

yum -y install nodejs