I have a class which is inside library.js:
function library(){}
library.prototype.open = function(){}
library.prototype.close = function(){}
library.prototype.remove = function(){}
var library = new library();
How could I expose this class?
According to Node docs:
The module.exports object is created by the Module system. Sometimes this is not acceptable; many want their module to be an instance of some class. To do this assign the desired export object to module.exports. Note that assigning the desired object to exports will simply rebind the local exports variable, which is probably not what you want to do.
From this point, you need to change:
var library = new library();
to
module.exports = new library();
don't need
var library = new library();
instead,
module.exports = library;