Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to import an instance of "io" in socket.io-client in ES6? #1055

Closed
crazyyi opened this issue Jan 9, 2017 · 6 comments
Closed

How to import an instance of "io" in socket.io-client in ES6? #1055

crazyyi opened this issue Jan 9, 2017 · 6 comments

Comments

@crazyyi
Copy link

crazyyi commented Jan 9, 2017

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').

@violetlight
Copy link

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

@faizalpribadi
Copy link

import ioClient from 'socket.io-client'

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

@crung
Copy link

crung commented Sep 26, 2018

how do you pass options in this case?

@Neudson01
Copy link

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);`

@OSG-Proj
Copy link

Importing doesnt work. It says fetch module import failed

@ushicode
Copy link

ushicode commented Dec 8, 2021

This should work.

import express from "express"
import http from 'http'
import {Server, Socket} from 'socket.io'

const app = express()
const server = http.createServer(app); 
const io = new Server(server)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants