vanilla-require
v1.0.2
Published
A package to import Vanilla JS Classes as Node.js Modules
Downloads
1
Maintainers
Readme
vanilla-require
The Node and npm have an incredible system for the inclusion of packages, made by require
.
However, to use packages one must export their modules, through module.exports
. Yet, it is not possible to use these packages on simple web pages because the web browser does not recognize the module.exports
.
This package allows you to develop simple classes to the web and export them to Node script as a module. In this sense, you can use your classes in the web browser and in the Node script, using the vanilla-require
package.
Vanilla JS: pure Javascript.
Installation
npm install --save vanilla-require
Example
See test/test.js
for another example.
A Vanilla class (Calculator.js
):
class Calculator {
sum(num1, num2){
return num1+num2;
}
}
Your Node code:
/* Include */
const vr = require('vanilla-require')(__dirname);
// Instance a Vanilla Class
const Calculator = vr.require('Calculator.js');
// Enjoy the Class!
let myCalc = new Calculator(),
a = 2, b = 3;
console.log('a:'+a+' b:'+b)
console.log('sum:'+myCalc.sum(a, b));
Also look ~
- License GPL v3
- Create by Leonardo Mauro ~ leomaurodesenv