{"_id":"5m","_rev":"9-22b3a6e4a79ee8254f17ef10c42cdec7","name":"5m","description":"is a near real time utility, 5mb or 5min","dist-tags":{"latest":"0.5.0"},"versions":{"0.1.0":{"name":"5m","version":"0.1.0","description":"is a near real time utility, 5mb or 5min logger util","author":{"name":"Gianluca Casati","url":"http://g14n.info"},"main":"5m.js","scripts":{"postversion":"git push origin v${npm_package_version}; npm publish; npm run push","test":"NODE_PATH=. node test.js"},"repository":{"type":"git","url":"git+https://github.com/fibo/5m.git"},"keywords":["logger","near","real","time"],"license":"MIT","bugs":{"url":"https://github.com/fibo/5m/issues"},"homepage":"http://npm.im/5m","gitHead":"7870a19715ab15f1e4733500cdfe27978e3d63b1","_id":"5m@0.1.0","_shasum":"7b8a8e79414467f9dfff3690d6064a657aa7ffc1","_from":".","_npmVersion":"3.10.8","_nodeVersion":"4.6.0","_npmUser":{"name":"fibo","email":"casati_gianluca@yahoo.it"},"dist":{"shasum":"7b8a8e79414467f9dfff3690d6064a657aa7ffc1","tarball":"https://registry.npmjs.org/5m/-/5m-0.1.0.tgz","integrity":"sha512-CwgvWUTqsHPZ9NTznYHmB68Pwf1AGg4ToL5Z6i0X3f5IO5QhwP4iBvxpTsA7knBvScYfkIU08MG9p/ZtKPmbyQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCZXDLrwMyhZS5j3msHXzGMhSCEFr8B/cIlbam/HAlptQIgESX+y7Yt26tZvOnuHZ5/aFe4jQYoNoMaOOz0RR8x8AE="}]},"maintainers":[{"name":"fibo","email":"casati_gianluca@yahoo.it"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/5m-0.1.0.tgz_1479603879450_0.896131093846634"},"directories":{}},"0.3.0":{"name":"5m","version":"0.3.0","description":"is a near real time utility, 5mb or 5min logger util","author":{"name":"Gianluca Casati","url":"http://g14n.info"},"main":"5m.js","scripts":{"postversion":"git push origin v${npm_package_version}; npm publish; npm run push","test":"NODE_PATH=. node test.js"},"repository":{"type":"git","url":"git+https://github.com/fibo/5m.git"},"keywords":["logger","near","real","time"],"license":"MIT","bugs":{"url":"https://github.com/fibo/5m/issues"},"homepage":"http://npm.im/5m","gitHead":"9af0730b0097361ad4f121f05b797406fcdcb1f6","_id":"5m@0.3.0","_shasum":"c5a6968eedc529e2877658488414ebfadecf4b7f","_from":".","_npmVersion":"3.10.8","_nodeVersion":"4.6.0","_npmUser":{"name":"fibo","email":"casati_gianluca@yahoo.it"},"dist":{"shasum":"c5a6968eedc529e2877658488414ebfadecf4b7f","tarball":"https://registry.npmjs.org/5m/-/5m-0.3.0.tgz","integrity":"sha512-HCMH063WfxhW33M6M59OdCweRKkst4NEY2H+Dco4JD9/YkWJq+e9xFLkRgWO8DYeDpVyccgvyZ4T4Vq7u5pJ1g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCzqs2XMLoMYEKtjNr3z4ktNPO5Zg8kVf2RmFeRlCKUQwIhAKN3p+3/a1MEqbK2+iOhokwOZlEixcP7l4iYg1dqea4p"}]},"maintainers":[{"name":"fibo","email":"casati_gianluca@yahoo.it"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/5m-0.3.0.tgz_1479652017438_0.14885381027124822"},"directories":{}},"0.4.0":{"name":"5m","version":"0.4.0","description":"is a near real time utility, 5mb or 5min","author":{"name":"Gianluca Casati","url":"http://g14n.info"},"main":"5m.js","scripts":{"lint":"standard *.js","postversion":"git push origin v${npm_package_version}; npm publish; npm run push","test":"FIVEM_TIMEOUT_MILLISECONDS=2000 NODE_PATH=. node test.js"},"repository":{"type":"git","url":"git+https://github.com/fibo/5m.git"},"keywords":["logger","near","real","time"],"license":"MIT","bugs":{"url":"https://github.com/fibo/5m/issues"},"homepage":"http://g14n.info/5m","gitHead":"2cc301e49d9f693719921a1ec6f1c5c03e7348ad","_id":"5m@0.4.0","_npmVersion":"5.0.3","_nodeVersion":"8.1.0","_npmUser":{"name":"fibo","email":"casati_gianluca@yahoo.it"},"dist":{"integrity":"sha512-Y376mlXE+CV6gmL+BxC4J+VWEo4AR1EJUxKqL7i+l0KQtMh/CpyiWigGX8pZIktM9giSWr7768UTnBIwbRqvvw==","shasum":"8b155f3250629071ee04175b43746a65cced04d4","tarball":"https://registry.npmjs.org/5m/-/5m-0.4.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCbarcKRdbvFYzAj3vB11earvbQ8ILaTPuAYZCi8icQZAIgYDLJ1yWVK1Xe8uvUeXi0dc2BLFcjpUdQL9agEDxcxVc="}]},"maintainers":[{"name":"fibo","email":"casati_gianluca@yahoo.it"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/5m-0.4.0.tgz_1498138391433_0.1773559176363051"},"directories":{}},"0.4.1":{"name":"5m","version":"0.4.1","description":"is a near real time utility, 5mb or 5min","author":{"name":"Gianluca Casati","url":"http://g14n.info"},"main":"5m.js","scripts":{"lint":"standard *.js","postversion":"git push origin v${npm_package_version}; npm publish; gut push origin master","test":"FIVEM_TIMEOUT_MILLISECONDS=2000 NODE_PATH=. node test.js"},"repository":{"type":"git","url":"git+https://github.com/fibo/5m.git"},"keywords":["logger","near","real","time"],"license":"MIT","bugs":{"url":"https://github.com/fibo/5m/issues"},"homepage":"http://g14n.info/5m","gitHead":"8f8ccdf8596eb84fb16f6dff8bf54acd811079b9","_id":"5m@0.4.1","_npmVersion":"5.0.3","_nodeVersion":"8.1.0","_npmUser":{"name":"fibo","email":"casati_gianluca@yahoo.it"},"dist":{"integrity":"sha512-2f1y24fctWb+doR1FcRx/cOE5b4n6UmRuJFFZOyfJ503OyOEMueS+g0fg6c0t5MlLePgTBFOJ/qzKabNTsAjWw==","shasum":"51e19b6589d919c70dbfff1b240ccd9bf7e02b44","tarball":"https://registry.npmjs.org/5m/-/5m-0.4.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC8MhBU7Q8PigbXpI431ERJb3amTW11vlxjQc19BAdDYAiEAhDdNM6YUEy0Wbj/+FO7GiSlXgKyWdj+8Cym8KJAFD3E="}]},"maintainers":[{"name":"fibo","email":"casati_gianluca@yahoo.it"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/5m-0.4.1.tgz_1498146702818_0.6821288373321295"},"directories":{}},"0.4.2":{"name":"5m","version":"0.4.2","description":"is a near real time utility, 5mb or 5min","author":{"name":"Gianluca Casati","url":"http://g14n.info"},"main":"5m.js","scripts":{"lint":"standard *.js","postversion":"git push origin v${npm_package_version}; npm publish; git push origin master","test":"FIVEM_TIMEOUT_MILLISECONDS=2000 NODE_PATH=. node test.js"},"repository":{"type":"git","url":"git+https://github.com/fibo/5m.git"},"keywords":["logger","near","real","time"],"license":"MIT","bugs":{"url":"https://github.com/fibo/5m/issues"},"homepage":"http://g14n.info/5m","gitHead":"f6b5f459a4815ab9b7b81a313c45feeaca6ee921","_id":"5m@0.4.2","_npmVersion":"5.0.3","_nodeVersion":"8.1.0","_npmUser":{"name":"fibo","email":"casati_gianluca@yahoo.it"},"dist":{"integrity":"sha512-G2VqlQqqLYqZagnrV0REBES0ZJZgU1wh9utjnWL8CwqcBCfb1Gc1VR0GMinufWgxakYsxm2NfQI0vjKo4AIVIA==","shasum":"61e3a35e1d6564b5ae89a60a0d495ad2a40dc3ac","tarball":"https://registry.npmjs.org/5m/-/5m-0.4.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDydbEBAoIxh/xxkIMRMXwKzNanbyGJsojLTmgPBZlwEgIhAOQtDJTusgFu9qghWPvOyorI/+ZT1em9MjMMCLX1s5we"}]},"maintainers":[{"name":"fibo","email":"casati_gianluca@yahoo.it"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/5m-0.4.2.tgz_1498146838690_0.5979965629521757"},"directories":{}},"0.5.0":{"name":"5m","version":"0.5.0","description":"is a near real time utility, 5mb or 5min","author":{"name":"Gianluca Casati","url":"http://g14n.info"},"main":"5m.js","scripts":{"lint":"standa","markdown2code":"markdown2code --lang javascript README.md > ${npm_package_main}","postversion":"git push origin v${npm_package_version}; npm publish; git push origin master","test":"FIVEM_TIMEOUT_MILLISECONDS=2000 NODE_PATH=. node test.js"},"repository":{"type":"git","url":"git://github.com/fibo/5m.git"},"keywords":["logger","near","real","time"],"license":"MIT","bugs":{"url":"https://github.com/fibo/5m/issues"},"homepage":"http://g14n.info/5m","devDependencies":{"markdown2code":"^0.3.0","standa":"^2.1.0"},"gitHead":"2e3b1386fc5f68394d06df33209bc436a949d15d","_id":"5m@0.5.0","_npmVersion":"6.1.0","_nodeVersion":"8.9.3","_npmUser":{"name":"fibo","email":"casati_gianluca@yahoo.it"},"dist":{"integrity":"sha512-KOyXwGrbAoIazyYBTn3GZmXjAEgMYkjax1mg3aUdtVjy6W3+VJzq88drXFWEk7Kc9huuKlq/OHTWBIOX7Gz37g==","shasum":"bf33f0abbf56514bf061b7faba2bcd13a8e3252f","tarball":"https://registry.npmjs.org/5m/-/5m-0.5.0.tgz","fileCount":5,"unpackedSize":7753,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbP6ARCRA9TVsSAnZWagAA1zoP/jiVURlfizMjwPvX6vFr\npEJslvuSziTnHJxuq/CcmPOG6Y9BHerUaH5zY/5Y0gWaI7CwiykU0YBn/5PS\nhdMMU4JOynmgDgJDm8jtemdLsj2IlzYoXOGv72C0QD07xR+hiEpXy0IHnFxv\ny+/g6VaBPK8MV/kgGcKIxKnusFPHGuktuINR/0wgPqEwHkqN7CcrT44u9GOk\nqM5S5BACKYENqVJZqqXUMd3GKlvXX7cCI1t6hkHyp/t0RLPY+HCPioz8/OZQ\nC23+bsnHXyiZbH8MK8DIbNZ8N2Knb1Su3tKNR/u0y4o5AF8Kim0yyMAGdJ7o\n+heBp6wvHi0y70rgTds9cmke+FtXDSJkCXVYLxHyvnMBU/o466dBeUfVHQgV\nyjpm4xhhkdaHpXe8cfBFUDtNNfU1s6rQcuja/W9cqb3nAIVYz55nU447I0mB\nOfXD618Qz3TBo/yQU7sk8hFizR3fzh6I5M63ffSBPeWF0EqZEhAiNnTbdgRl\nWNy1rdHE7S/uq56xsrljAuLkbzzMHZc8bO66iswTmStRwGPs/WrSGyw5hFvp\nESEPyTN5duXybHe2BXQe1Un+X3DQwbHP/pfOYL3Kg5oGNU+R9jQquE08PqaV\nLfBKZzLb3bWE7Gi7uqnsGb7C/+vdqK4/IrE+qshR3uZ9nY59A3akn6qigG+D\nfa1q\r\n=2kZw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCDkT9DVBHa1V96FTvDBYaL4kMsGDE1/BSWPm6dsNDr0gIhAIMWdWhJLZv5Oaj5XwTfz0uLQjmWUqsU0eAF0IKLKaP/"}]},"maintainers":[{"name":"fibo","email":"casati_gianluca@yahoo.it"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/5m_0.5.0_1530896401493_0.963735976242625"},"_hasShrinkwrap":false}},"readme":"# 5m\n\n> is a near real time utility, 5mb or 5min\n\n[![KLP](https://img.shields.io/badge/kiss-literate-orange.svg)](http://g14n.info/kiss-literate-programming)\n\n[Installation](#installation) |\n[Use case](#use-case) |\n[Annotated source](#annotated-source) |\n[License](#license)\n\n## Installation\n\n```bash\nnpm i 5m\n```\n\n## Use case\n\n> I use this package with [debug] and [aws-sdk] to upload logs on S3.\n\nThen there is a trigger that feeds every file created on S3 to an AWS Lambda\nwhich sends file content to a server that broadcast it using [socket.io].\nYes I know there are other cool tools like CloudWatch, Kinesis, etc.\n(but **5m** is free as in speach and free as in beer too ;)\n\nThe cool part is that it is possible to trigger an AWS Lambda every time\na new file is created, and for example load it on a database.\n\nHere is an example code to achieve logging and upload on S3.\n\n```js\n// File: log.js\n//\n// Prints to STDOUT if DEBUG environment variable is set properly.\n// Uploads logs on some S3 bucket.\n//\n//     const log = require('./log')\n//     log('Hello world')\n//\n\nconst AWS = require('aws-sdk')\nconst debug = require('debug')\nconst fiveM = require('5m')\n\nconst s3 = new AWS.S3()\n\n// Use package name as namespace for logging, just as an example.\nconst pkg = require('./package.json')\nconst namespace = pkg.name\nconst debug5m = debug(`${namespace}:5m`)\nconst debugPkg = debug(namespace)\n\nconst writeOnS3 = (data) => {\n  const Bucket = 'my-bucket'\n\n  const tstamp = new Date().getTime()\n  const Key = `my/path/${tstamp}.log`\n\n  s3.upload({ Bucket, Key }, error => {\n    if (error) debug5m(error)\n    else debug5m()\n  })\n}\n\nfunction log (message) {\n  const tstamp = new Date().getTime()\n  const record = `${tstamp} ${namespace} ${message}`\n\n  fiveM(namespace, writeOnS3)(record)\n  debugPkg(message)\n}\n\nmodule.exports = log\n```\n\n## Annotated source\n\nStore data in a namespaced bucket, as well as its function to flush data.\n\n```javascript\nvar bucket = {}\nvar flush = {}\n```\n\nConsidering 1 char should be 1 byte, and dates are expressed in milliseconds,\nthe following constants express *5 MB* and *5 minutes*.\nAproximation is ok, since we want to achieve a near real time.\nThe timeout used for flushing data can be set, for testing or other purpouse\nvia the `FIVEM_TIMEOUT_MILLISECONDS` environment variable.\n\n\n```javascript\nconst fiveMb = 1024 * 1024 * 5\nconst fiveMin = 300 * 1000\nconst flushTimeout = process.env.FIVEM_TIMEOUT_MILLISECONDS || fiveMin\n```\n\nMake sure no data is lost on exit.\n\n```javascript\nprocess.on('exit', () => {\n  for (var namespace in bucket) flush[namespace]()\n})\n```\n\nCreate the **5m** function.\n\nSince *5m* is allowed as npm package name, but not as JavaScript\nidentifier, using a roman number like *Vm* can be confusing, so maybe\nnaming the function as *fiveM* is a good idea.\n\n```javascript\n/**\n * **@param** `{String}` namespace\n * **@param** `{Function}` write\n *\n * **@returns** `{Function}` logger\n */\nfunction fiveM (namespace, write) {\n```\n\nCreate the namespaced *flush* function: write data and clean up.\n\n```javascript\n  flush[namespace] = () => {\n    if (bucket[namespace]) {\n      write(bucket[namespace])\n\n      delete bucket[namespace]\n    }\n  }\n```\n\nCreate the **logger** function.\n\n```javascript\n  /**\n   * @param {*} data\n   */\n  return function logger (data) {\n```\n\nIf necessary, initialize data bucket and set timeout to flush it later.\n\n```javascript\n    if (typeof bucket[namespace] === 'undefined') {\n      bucket[namespace] = ''\n\n      setTimeout(flush[namespace], flushTimeout)\n    }\n```\n\nAppend data to named bucket.\n\n```javascript\n    bucket[namespace] += data\n```\n\nCheck if data is bigger than *5 MB*.\n\n```javascript\n    const exceededSpace = bucket[namespace] && (bucket[namespace].length > 0) && (bucket[namespace].length > fiveMb)\n```\n\nIf yes, flush it!\n\n```javascript\n    if (exceededSpace) flush[namespace]()\n  }\n}\n```\n\nExport *5m* function.\n\n```javascript\nmodule.exports = fiveM\n```\n\n## License\n\n[MIT](http://g14n.info/mit-license)\n\n[debug]: https://www.npmjs.com/package/debug \"debug\"\n[aws-sdk]: https://www.npmjs.com/package/aws-sdk \"aws-sdk\"\n[socket.io]: https://socket.io/ \"socket.io\"\n","maintainers":[{"name":"fibo","email":"casati_gianluca@yahoo.it"}],"time":{"modified":"2022-06-12T14:08:12.708Z","created":"2016-11-20T01:04:40.010Z","0.1.0":"2016-11-20T01:04:40.010Z","0.3.0":"2016-11-20T14:26:59.599Z","0.4.0":"2017-06-22T13:33:12.475Z","0.4.1":"2017-06-22T15:51:43.922Z","0.4.2":"2017-06-22T15:53:59.640Z","0.5.0":"2018-07-06T17:00:01.552Z"},"homepage":"http://g14n.info/5m","keywords":["logger","near","real","time"],"repository":{"type":"git","url":"git://github.com/fibo/5m.git"},"author":{"name":"Gianluca Casati","url":"http://g14n.info"},"bugs":{"url":"https://github.com/fibo/5m/issues"},"license":"MIT","readmeFilename":"README.md"}