A package that allows to create and store data in a temporary file. The stored data will be returned in same type as stored while retrieving from the file. Also, a dedicated method available to remove the file manually.
tmpkoppu
- name inspired from a combination of english-tamil words, where tmp
from temporary and koppu
(கோப்பு) which means file in tamil. As the name refers, it's a temporary-file.
npm install tmpkoppu
Importing package can be done in either ES module or CommonJS module way
import { store, get, remove } from 'tmpkoppu'
or
const { store, get, remove } = require('tmpkoppu')
This method used to create a temporary file under the server's /tmp
directory. The data that needs to be stored in the file can be passed as first param.
store(data: any)
It will return a promise resolved with path
of the generated file. The path will be used to perform further operations like retrieving data and removing file manually.
store(1234).then(path => console.log(path)).catch(err => console.log(err));
This method used to retrieve data from the created file. It requires a param: path
to access the file content.
get(path)
It will return a promise resolved with actual data in the same type. For ex, if number 1234
is stored then the returned data type will be number.
get(path).then(val => console.log(val, typeof val)).catch(err => console.log(err));
This method used to remove the file created under /tmp
directory. It requires a param: path
to remove the file.
remove(path)
It will return a promise resolved with a success message File removed!
.
remove(path).then(successMsg => console.log(successMsg)).catch(err => console.log(err));
Abu - abudesk95@gmail.com