Skip to content

leomaurodesenv/vanilla-require

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vanilla-require

GPLv3 license npm JsClasses GitHub Codacy Badge


The Node.js and npm have an incredible system for the inclusion of packages, made by require. However, for use packages one must export their modules, through module.exports. Yet, it is not possible to use these packages on simple web classes 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.js script as a module. In this sense, you can use your classes in the web browser (pure Javascript) and in the Node.js 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 ~

About

A package to import Vanilla JS Classes as Node.js Modules

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published