1.0.4 • Published 5 years ago

file-listen-process v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

file-listen-process

file-listen-process is a NodeJS library listen for files with a specific extension in a directory, rename and backup the file as it arrives.

Example:

File arrive: STOCK.csv

File renamed: STOCK-1549004279028-0.dat

File backup: _backup/STOCK-1549004279028-0.dat

Installation

Use the package manager npm to install file-listen-process.

npm i file-listen-process

Usage

const flp = require('file-listen-process');

const listener = new flp.Listener({
    directory: './dump',
    interval: 5000,
    fileext: '.csv',
    typematch: /[^\_]*/,
    renametemplate: '[TYPE]-[TIMESTAMP]-[COUNTER].dat'
});

listener.listen((err) => {
    console.log(err.message);
});

listener.on('loaded', (files) => {
    console.log(files);
});

listener.on('log', (event) => {
    console.log(event);
});

Listener Options

option (environment variable)

directory (FILELOADER_DIRECTORY)

interval (FILELOADER_INTERVAL) *** timer interval in seconds

fileext (FILELOADER_EXT) *** like .csv

typematch (FILELOADER_TYPEMATCH) *** regex match

mustrename (FILELOADER_MUSTRENAME) *** true/false to rename file

renametemplate (FILELOADER_RENAMETEMPLATE) *** TYPE,TIMESTAMP,COUNTER

mustbackup (FILELOADER_MUSTBACKUP) *** true/false to backup file

backupdirectory (FILELOADER_BACKUPDIRECTORY) *** directory for file backup

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago