Socket.io-client: How to import an instance of "io" in socket.io-client in ES6?

Created on 9 Jan 2017  ·  5Comments  ·  Source: socketio/socket.io-client

Sorry to bring up this here. I couldn't find any information of importing it in ES6 syntax. Is it supported now? Do I have to use require('socket.io-client')? If I use import * as io from 'socket.io-client' I have to use io.connect('localhost'). But if I use require('socket.io-client') I just need to use io('localhost').

Most helpful comment

Doing import io from 'socket.io-client' will give you a direct reference to io.

All 5 comments

Doing import io from 'socket.io-client' will give you a direct reference to io.

import ioClient from 'socket.io-client'

let io = ioClient('http://your-host')

how do you pass options in this case?

Try doing something like this:

`import express from 'express';
import http from 'http';
import SocketIO from 'socket.io';
import compression from 'compression';
import {validNick, findIndex, sanitizeString} from '../shared/util';

let app = express();
let server = http.Server(app);
let io = new SocketIO(server);`

Importing doesnt work. It says fetch module import failed

Was this page helpful?
0 / 5 - 0 ratings