-2

when i try to use command node file.js terminal show syntax error in this line {export default function} SyntaxError: Unexpected token export

         const io = require('socket.io-client')
        var os = require("os");
        export default function () {
            const socket = io.connect('http://' + os.hostname() + ':3000')

            function registerHandler(onMessageReceived) {
                socket.on('message', onMessageReceived)
            }

            function getAvailableUsers(cb) {
                socket.emit('availableUsers', null, cb)
            }

            return {

                getAvailableUsers,
                registerHandler
            }
        }

here is my code any help if i remove export i have the same error with default keyword

1 Answers1

0

Most likely your Node project is not setup to use ES6 module loading.

Complete response here export default routes; SyntaxError in NodeJS

Try yo use the module.exports syntax as described here module.exports vs. export default in Node.js and ES6

Andrea Franchini
  • 548
  • 4
  • 14