Reputation: 327
I want to make a little chat app for learning and I created many js files which for separate like modular but I got some error.
this is my boot.js file
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var admin = io.of('/app'),
client = io.of('');
module.exports.app = app;
module.exports.http = http;
module.exports.io = io;
this is my routes.js file
module.exports = {
start: function(app) {
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
}
};
this is my chat.js
var boot = require('./boot');
require('./routes')(boot.app).start();
http.listen(3000, function(){
console.log('listening on *:3000');
});
when i run the node i got this error
require('./routes')(boot.app).start();
^
TypeError: require(...) is not a function
how could I use the variables which in the boot.js to other js files?
help me please.
Upvotes: 1
Views: 310
Reputation: 9931
You are making a small mistake here. Below is the correct one.
require('./routes').start(boot.app);
routes
module exports an object where you can call start
and use that function.
Upvotes: 2