1

I have following code in node.js.

const express = require("express");
var socket = require("socket.io");

class Server {

    constructor() {
        this.app = express();
        this.port = process.env.PORT || 89;
        this.host = process.env.HOST || `192.168.43.173:89`;
    }

    includeRoutes() {
    }

    appExecute() {

        var server = this.app.listen(this.port, () => {
            console.log(`Listening on http://${this.host}`);
        });     
        var io = socket(server);
    }
}
const server = new Server();
server.appExecute();

below are the dependencies exist in package.json file.

"express": "^4.17.1",
"socket.io": "^2.3.0"

I am facing an issue when the line is executed var io = socket(server);

Error Details.

Unexpected Token ...options.

Here is the screenshot.

enter image description here

Can you please suggest something? If you need more info, please let me know

1 Answer 1

1

Upgrade Node.js to a current version, or use the --harmony flag when starting it.

The ... is an ES6 spread operator, and is supported normally in current versions of Node.js.

See also: https://nodejs.org/en/docs/es6/

Sign up to request clarification or add additional context in comments.

3 Comments

great answer but i think it would be better if it includes a brief how to update :D
Thank You very much, Everything works perfectly after installing the latest version of node.js.
@mAhMoUdDaFeR Literally just have to go to the Node.js website, click the big green download button, and run the installer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.