Reputation: 34061
i downloaded an example about using nodejs and requirejs. Consider this snippet code.
define(['express', 'module', 'path'], function (express, module, path) {
var app = express.createServer();
app.configure(function() {
app.use(express.logger({ format: ':method :url :status' }));
var filename = module.uri;
app.use(express.static(path.dirname(filename) + '/static'));
});
return app;
});
what is here the module "module"? When i look in my depencies file, "module" doesn't exist.
{
"name": "node-requirejs-example",
"version": "0.0.1",
"dependencies": {
"express": "2.5.0",
"requirejs": ">=1.0.0",
"socket.io": ">=0.8.7",
"underscore": ">=1.2.1"
}
}
when i gonna use requirejs then is underscore important?
Upvotes: 0
Views: 578
Reputation: 19377
There is a specially named requirejs dependency called 'module' which you can use to look up additional information from the requirejs internals. This is typically used for passing additional configuration data. From the requirejs config api documentation:
There is a common need to pass configuration info to a module. That configuration info is usually known as part of the application, and there needs to be a way to pass that down to a module. In RequireJS, that is done with the config option for requirejs.config(). Modules can then read that info by asking for the special dependency "module" and calling module.config().
See also Magic Modules from the wiki:
This module gives you information about the module ID and location of the current module:
In that section, he has an example of using module.uri, like in your original code snippet:
define(['module'], function(module){
console.log(module.id);
console.log(module.uri);
});
Upvotes: 4