2

I want to use socket.io and https://socket.io/get-started/chat/ user this link to understand when I try to run node index.js

I got an error

const WebSocket = require('./lib/WebSocket');
^^^^^ SyntaxError: Use of const in strict mode.
    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 Server.init (C:\WEBLER\Socket.io\node_modules\socket.io\node_modules\engi ne.io\lib\server.js:119:16)
    at new Server (C:\WEBLER\Socket.io\node_modules\socket.io\node_modules\engin e.io\lib\server.js:65:8)
    at Function.attach (C:\WEBLER\Socket.io\node_modules\socket.io\node_modules\ engine.io\lib\engine.io.js:123:16)

I looked at problems . generally people say upgrade version of node.js when I run node --version

answer is 2.7.4 I tried

npm cache clean -f
npm install stable

node --version

but it wasn't solved. How can I solve problem?

deceze
  • 510,633
  • 85
  • 743
  • 889

1 Answers1

0

const is only available in node v4.0 onwards I believe. You can do as Edilson suggested and use var, or upgrade node from 2.7.4 to a version that supports const. Also, take jsNovice advice and use nvm. Here is a link to the same issue someone else had: https://github.com/felixrieseberg/npm-windows-upgrade/issues/108

johnny_mac
  • 1,801
  • 3
  • 20
  • 48