Why are some functions assigned to be properties of the exports object? For example this:
exports.index = function(req, res){
res.render('index', { title: 'Hello' });
};
Whats the point of exports?
Why are some functions assigned to be properties of the exports object? For example this:
exports.index = function(req, res){
res.render('index', { title: 'Hello' });
};
Whats the point of exports?
Exports are the publicly visible interface of a module. When using a module you can access anything that was exported from the module.
This allows you to hide private implementation details of your module and only export the objects, properties and functions you want to be able to be used from outside.
Modules are one solution to the Javascript problem of lack of privacy and classes. Enabling you to encapsulate private data and behaviours effectively.