This project is under active Development
and may be unstable or contain bugs. We do not recommend using it in a production environment.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install node-logtify
const { nodeLogtify } = require('node-logtify')
const express = require("express");
const app = express();
const { nodeLogtify, readLog } = require('node-logtify');
const PORT = 3000;
app.use(nodeLogtify);
app.use((req, res, next) => {
setTimeout(() => {
const dataLog = readLog()
// Save the log to Database
console.log('dataLog:', readLog)
}, 500);
next()
})
app.get('/', (req, res) => {
return res.status(200).json('Hello World !);
});
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
});
const express = require("express");
const app = express();
const cron = require('node-cron');
const { nodeCronLogtify } = require('node-logtify');
const PORT = 3000;
cron.schedule('* * * * *', () => {
/**
* required :
* 1. a file for store logs, example: cron.log
* 2. State for log, example : Cron Running
*
* if a state is object : you must convert in JSON Stringify
*
**/
nodeCronLogtify('cron.log', 'Cron Running')
nodeCronLogtify('cron.log', JSON.stringify({message: 'Cron Running'}))
});
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
});