Struggling to configure express.io with individual files for each route? Check out the examples provided.
Currently, I have a typical Express setup that I want to transition to express.io:
Project
app.js
routes
servepage.js
Views
servepage.jade
public
main.js <-- client side javascript
In the example they provide for routing, the code is placed in app.js like so:
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 tried moving just the route definition to app.js:
app.io.route('ready', servepage);
But this resulted in the error:
TypeError: undefined is not a function
How can I set up the application using more than just app.js? What could be causing this error?
EDIT: In servepage.js, I am including:
var express = require('express');
Rather than:
var express = require('express.io');
To avoid errors.