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

Problems with Express and socket.io #973

Closed
nojaf opened this issue Jun 22, 2017 · 1 comment
Closed

Problems with Express and socket.io #973

nojaf opened this issue Jun 22, 2017 · 1 comment

Comments

@nojaf
Copy link

nojaf commented Jun 22, 2017

I'm having some errors with the following code

// @flow
import type { $Request, $Response} from 'express';

const hbs = require("hbs");
const express = require("express");
const app = express();
app.set("view engine", "hbs");
console.log( __dirname + "/views");
app.set("views", __dirname + "/views");

// $@FlowFixMe
const http = require("http").Server(app);
const io = require('socket.io')(http);

io.on("connection", () => {
    console.log("new user connected");
});

app.get('/', (req: $Request, res: $Response) => {
    res.render("index");
});

http.listen(8300, () => {
    console.log("Server running on 8300");
});

flow output:

PS C:\temp\express-hbs> flow                                                                
server/index.js:4                                                                           
  4: const hbs = require("hbs");                                                            
                         ^^^^^ hbs. Required module not found                               
                                                                                            
server/index.js:12                                                                          
 12: const http = require("http").Server(app);                                              
                                  ^^^^^^ property `Server`. Property not found in           
 12: const http = require("http").Server(app);                                              
                  ^^^^^^^^^^^^^^^ module `http`                                             
                                                                                            
server/index.js:13                                                                          
 13: const io = require('socket.io')(http);                                                 
                        ^^^^^^^^^^^ socket.io. Required module not found                    
                                                                                            
                                                                                            
Found 3 errors                                                                              

So the .Server thing can be ignored by the $FlowFixMe but how can I tell flow to be cool with socket.io? There are no definition files for socket.io or hbs.

I'd like some workarounds and I'm not sure what my options are here.

@gantoine
Copy link
Member

gantoine commented Jul 3, 2017

@nojaf I've just opened a PR which adds definitions for the socket.io server API. Once merged it should address your issue.

Also, flow-typed install should have generated a stub for socket.io, so check that the stub does in fact exist in your project.

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

2 participants