This library allows you to include, in-place, common Javascript files (not modules) into your Node.js application and evaluate their script in the global namespace, kind like PHP does.
npm install @eugabrielsilva/js-include
// Declare the module
const includes = require('@eugabrielsilva/js-include');
// Include the file
includes.__includeFile('./inc/myfile.js');
eval(includes.myfile);
// Declare the module
const includes = require('@eugabrielsilva/js-include');
// Include the directory
includes.__includeDir('./inc');
for (let file in includes.inc) {
eval(includes.inc[file]);
}
__includeFile()
and __includeDir()
do not check for files existence.
If you want to check if a file exists before including it, and throw an error if not, use __requireFile()
and __requireDir()
equivalents.
Library developed and currently maintained by Gabriel Silva.