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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.