Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pauldotknopf/hot-instance
A helper node library to keep a js file "hot" by watching the file for changes.
https://github.com/pauldotknopf/hot-instance
Last synced: 17 days ago
JSON representation
A helper node library to keep a js file "hot" by watching the file for changes.
- Host: GitHub
- URL: https://github.com/pauldotknopf/hot-instance
- Owner: pauldotknopf
- License: mit
- Created: 2016-07-19T11:57:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-07-20T01:17:23.000Z (over 8 years ago)
- Last Synced: 2024-10-13T10:53:23.300Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hot-instance
[![NPM version][npm-image]][npm-url] [![Dependency Status][daviddm-image]][daviddm-url]
> A helper library to keep a js file "hot" by watching the file for changes.
```npm install hot-instance```
## A quick demo
**```live.js```**
```js
module.exports = function() {
return 'Update this string value to watch it reload automatically!';
}
```**```index.js```**
```js
var express = require('express');
var app = express();
var hot = require('hot-instance');var testJsFile = hot(require.resolve('./live')); // full paths required
// "instance" is exported from "live.js". It will be auto-reloaded when the file changes.
console.log(testJsFile.instance());app.get('/', function (req, res) {
// let the user know what the value is now
res.send(testJsFile.instance());
});app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
```## Documentation
```hot``` is a function. It takes a single arguement, ```module```, which must be a fully qualified path to the javascript file you wish to load and watch. It returns a ```LiveInstance``` object.
### ```LiveInstance```
#### ```instance``` - This is the actual exported contents of your hot file. This will be auto-updated as your file changes. If the file you are watching is deleted, it will be ```null```. It will continue watching for the file to re-appear.
#### ```exists``` - A ```bool``` that indicates if the file you are watching currently exists. If the file you are watching becomes deleted, this will be ```false```, and ```instance``` will be ```null```.[npm-image]: https://badge.fury.io/js/hot-instance.svg
[npm-url]: https://npmjs.org/package/hot-instance
[daviddm-image]: https://david-dm.org/pauldotknopf/hot-instance.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/pauldotknopf/hot-instance