https://github.com/eugabrielsilva/js-include
PHP-like include library for Node.js
https://github.com/eugabrielsilva/js-include
include javascript-module nodejs
Last synced: 6 days ago
JSON representation
PHP-like include library for Node.js
- Host: GitHub
- URL: https://github.com/eugabrielsilva/js-include
- Owner: eugabrielsilva
- License: mit
- Created: 2021-11-14T20:02:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-09T20:33:42.000Z (over 2 years ago)
- Last Synced: 2025-04-21T11:19:28.630Z (about 1 month ago)
- Topics: include, javascript-module, nodejs
- Language: JavaScript
- Homepage: https://npmjs.com/package/@eugabrielsilva/js-include
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# js-include
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.### Installation
```
npm install @eugabrielsilva/js-include
```### Usage (single file)
```js
// Declare the module
const includes = require('@eugabrielsilva/js-include');// Include the file
includes.__includeFile('./inc/myfile.js');
eval(includes.myfile);
```### Usage (directory)
```js
// 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]);
}
```### Checking files existence
`__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.
### Credits
Library developed and currently maintained by [Gabriel Silva](https://github.com/eugabrielsilva).