2.2.2 • Published 4 years ago

letsrequire v2.2.2

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
4 years ago

letsrequire

Overrides require() and adds hot-reload functionality

Just add require('letsrequire') and run your application with simple "node filename.js" and it will hot-load your dependencies. So, you are not required to do any change in your existing application.

Only to be used for development purposes

Install

npm install letsrequire

Usage

require('letsrequire');

API

Nothing as such, just add the 'require' statement and you are good to go. As the library overrides the native implementation of require, you do not need to make any other change in your project/code.

Errors - but nothing breaks..!! :)

There can be few errors as we are hot reloading the dependencies on file changes. The errors are console logged and we wait for the next file change to reload the file. But the system still works fine with the earlier version of the file. So NOTHING breaks..!! :)

How does it work

It uses the native require module to serve the core purpose. Watches for file changes on the application working directory that are required by this library and not all the files. Cleans the require cache when it detects that a re-require is required. Replaces all of your instances with the new module. Straight simple logic...

Note..!!

Does not hot-reload node-modules, as you are expected to restart your process. This should only be the scenario where you have altered your dependencies

Example :

A dependency file to return a simple string

    let anythingdynamic = function() {
        return "this string can be changed in runtime, and server will serve the updated one";
    }

    module.exports = {
        anythingdynamic
    }

A simple server, to response the string from the above file

    require('letsrequire');// <-- this is the new thing

    var http = require('http');

    // loading the dependencies just like before
    let reply = require("./reply.js");

    http.createServer(function (req, res) {
        // use the dependency as you usually do
        res.write(reply.anythingdynamic());
        res.end();
    }).listen(8080);

Related

  • invalidate-module - Removes a module and all of its dependents from the require cache
  • require-reload - require-reload facilitates hot-reloading files in node.js. Each call will re-fetch the file/module and require it.
  • hotter-require - Modifies require to enable hot-reloading of code modules.

License

Apache-2.0 © Rajdeep Deb

2.2.2

4 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago