Skip to content

Instantly share code, notes, and snippets.

View theouerd's full-sized avatar
😊
I may be slow to respond.

Oussama theouerd

😊
I may be slow to respond.
View GitHub Profile
@theouerd
theouerd / process.js
Created January 7, 2023 19:37
simulate how to refresh token retreived from external API, based on it's expiration date to avoid invalid token error.
/**
* Make token
* @param {number} length Token length
* @param {number} expires_in Token expiration in seconds, default: 5 secs
*
* @return {Array}
*/
const makeToken = (length, expires_in = 5) => {
let token = '';
const characters =
@theouerd
theouerd / index.js
Created November 25, 2019 21:46
index.js file
global.CronJob = require('./cron.js');
@theouerd
theouerd / cron.js
Created November 25, 2019 20:43
a configuration file that specifies shell commands to run periodically on a given schedule.
const CronJob = require('cron').CronJob;
const Cron = require('./backup.js');
// AutoBackUp every week (at 00:00 on Sunday)
new CronJob(
'0 0 * * 0',
function() {
Cron.dbAutoBackUp();
},
@theouerd
theouerd / backup.js
Created November 25, 2019 20:35
Auto backup function.
const fs = require('fs');
const _ = require('lodash');
const exec = require('child_process').exec;
const path = require('path');
// Concatenate root directory path with our backup folder.
const backupDirPath = path.join(__dirname, 'database-backup');
const dbOptions = {
user: '<databaseUsername>',