0

How do I set up express.io when I have files for each route. I'm struggling to apply the examples.

I have a standard Express I'm trying to convert to express.io:

Project
    app.js
    routes
       servepage.js
    Views
       servepage.jade
    public
       main.js   <-- client side javascript

In the Routing example, they put this code in app.js:

var express = require('express.io');
  .... lots of Express routes omitted
app.io.route('ready', function(req) {
    req.io.emit('talk', {
        message: 'io event from an io route on the server'
    })
})

I put just the route definition in app.js:

app.io.route('ready', servepage);

and get:

TypeError: undefined is not a function

How do I set up the app using more than just app.js? And why is it giving me this error?

EDIT: The servepage.js file has:

var express = require('express');

and not:

var express = require('express.io');

because this generates an error.

Dirk
  • 3,073
  • 4
  • 31
  • 36

1 Answers1

1

Seems you omit the require statement of servepage.js file

servepage.js

module.exports = function(){ ... };

app.js

var servepage = require("./routes/servepage.js");
app.io.route('ready', servepage);
Luca Colonnello
  • 1,416
  • 12
  • 11
  • Hi, I do add it in - apologies for omitting it from the question, there is quite a long list of 'regular' (non express.io) routes. – Dirk May 23 '15 at 13:33