hotfunctionsmanager

0.0.5 • Public • Published

Hot Functions Manager

This module aims to read all files of a given directory in order to parse their content, supposed to be JavaScript functions. After being parsed, those functions will be available through a defined interface.

Installation

This module is available on NPM:

$ npm install hotfunctionsmanager

Features

  • Add a function object (write it or not to the filesystem)
  • Add a function from a script added while the process was running
  • Delete a function (also from the filesystem if wished)
  • Update functions considering the dedicated folder's content

How does it work ?

This module reads a given directory's files and evaluate their content. This content MUST be anonymous Javascript function. Those functions will be then available through a id-function interface, where the id of a function is its filename without extension.

For example, if there's a file "hello.js" that contains:

function () {
    console.log("Hello world!");
}

Then, the id of the function will be "hello".

It's on your own to write your functions with a correct syntax, unless the module will crash !

You can also adds functions while the process is running, and decide if this functions will be written to the filesystem or not. Keep in mind that there's a risk of overwritting files and functions if you specifies the same id of two differents functions.

If you've added new functions in the directory, you can analyse the directory once again with the updateFunctionsList() method.

How to use

Let's consider that you have a directory "myDirectory", that contains two files: "hello.js" and "goodbye.js". So, you can do the following:

var HotFunctionsManager = require("hotFunctionsManager");
 
// Construct your object
var myFunctions = new HotFunctionsManager("./myDirectory");
 
// Here, our object has been built, but our folder hasn't beed read yet
// This is triggered by the call of the init() method.
// Why ? Because, reading files involves I/O operations that may impact
// considerably your application's performances. Please, consider it.
myFunctions.init();
 
// And now, you can call your functions
myFunctions.getFunction("hello")();
 
// Add a function that will not be written to the filesystem
myFunctions.addFunction("fn1", function () {
    console.log("New function");
}, false, false);
 
// Add a function that will be written to the filesystem
myFunctions.addFunction("fn2", function () {
    console.log("New function - written");
}, true, false);
 
// Now let's say that you process has been running for 2~3 days, but
// you need to add new features... But, your project is on production
// environment, you can't kill the process... What do you do ?!
// Well, simply write your features in file, and run the following:
myFunctions.updateFunctionsList();
// Of course, your process must have predicted this behavior, and must
// then, running as a job an execution of all your defined functions
// (See myFunctions.getAllIds())

API

Please, check this folder for the API.

Readme

Keywords

none

Package Sidebar

Install

npm i hotfunctionsmanager

Weekly Downloads

4

Version

0.0.5

License

BSD

Last publish

Collaborators

  • stouf