Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meixg/cache-free-require
Require modules with no caching in Node.js.
https://github.com/meixg/cache-free-require
Last synced: 3 months ago
JSON representation
Require modules with no caching in Node.js.
- Host: GitHub
- URL: https://github.com/meixg/cache-free-require
- Owner: meixg
- Created: 2020-09-04T07:03:34.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-07-06T06:00:32.000Z (over 1 year ago)
- Last Synced: 2024-09-15T03:31:23.543Z (4 months ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cache-free-require
Require modules with no caching in Node.js.
## why
In developing Node.js apps, we need to restart Node.js server every time code changed. Using nodemon maybe a way to solve this. But when the Node.js server is too complicated, it's time consuming to restart.
`cache-free-require` is suitable when we frequently change a little parts of code.
`cache-free-require` can require a module with no cache, it will always read the file content.
## how
```javascript
const {freeCache} = require('cache-free-require');// can be string or RegExp
// if regExp.test(filename) === true or string === filename
// there will be no cache
freeCache([
/app\/index\.js/,
'/absolute/path/to/child',
]);require('app/index.js');
```or by single require
```javascript
const {cacheFreeRequire} = require('cache-free-require');
cacheFreeRequire('./path/to/module', __dirname);
cacheFreeRequire('some-module', __dirname);
```or
```javascript
const {makeRequire} = require('cache-free-require');
const cacheFreeRequire = makeRequire(__dirname);cacheFreeRequire('./path/to/module');
cacheFreeRequire('some-module');
```## notice
- Only support `.js` and `.json`, other file will be treated as `.js`.
- Only can be used on files with no state, otherwise the state will not be persisted.