I am using NodeJS. Is it possible to require a javascript file in node as we do in browsers? Because when I use the require() method it calls a javascript file that as no access to the global variables in my server.js it is like a "use strict" I guess. I needed to load my module and make it a continuation of the main file since my module depends on some global variables.
EDIT:
I have this server.js file:
var Settings = require("settings.js");
var Clients = require("clients.js");
var removePack = [];
/**HERE RUNS MY WEBSOCKET SERVER**/
...
...
//When a new socket connects:
io.on("connection", function(socket){
var socket.id = Math.random();
var client = Clients.create(socket.id);
});
Here my clients.js file:
exports.create = function(){
self.team = Settings.generateRandomTeam(); /*The problem is here. I can´t access the Settings variable*/
self.maxSpeed = Settings.maxSpeed;
...
...
return self;
}
EDIT 2:
When I use Settings = require("settings.js") I get the following error:
TypeError: Settings.generateRandomTeam() is not a function.
My settings.js file is like this:
Settings.generateRandomTeam = function(){
//Some code
}
module.exports = Settings;
Thanks!