JS

Use PM2 to Boot Start

Install PM2 globally using NPM

npm install pm2 -g

Start your script with pm2

pm2 start app.js
pm2 save

generate an active startup script

pm2 startup

pm2 unstartup

NOTE: pm2 startup is for startting the PM2 when the system reboots. PM2 once started, restarts all the processes it had been managing before the system went down.

In case you want to disable the automatic startup, simply use pm2 unstartup

If you want the startup script to be executed under another user, just use the -u <username> option and the --hp <user_home>:

pm2 flush -> remove pm2 logs


Node Backup Mongo


  const backupMongo = function () {
    const fileName = 'archive' + moment().format('YYYY-MM-DD-hh:mm') + '.gz'
    spawn = require("child_process").spawn;
    let backupProcess = spawn("mongodump", [
      "--host=52.9.218.54",
      "--port=27017",
      "--username=mohotdb",
      "--password=mohot12345",
      "--db=mohot",
      "--archive=" + fileName,
      "--gzip",
    ]);

    backupProcess.on("exit", (code, signal) => {
      if (code) console.log("Backup process exited with code ", code);
      else if (signal)
        console.error("Backup process was killed with singal ", signal);
      else console.log("Successfully backedup the database");
    });
  };

Javascript ... spread operator


var oldArray = [1,2,3]
var copyArray = [...oldArray]
var sortWithoutModify = [...oldArray].sort(sf)

var addOne = [...oldArray,newItem]

var oldObj = {
a:1,
b:1
c:1
}
var copyObj = {
...oldObj
}
var newObj = {
...oldObj,
d:1,
a:2
}


var oldArray = [1,2,3]
var copyArray = [...oldArray]
var sortWithoutModify = [...oldArray].sort(sf)

var addOne = [...oldArray,newItem]

var oldObj = {
a:1,
b:1
c:1
}
var copyObj = {
...oldObj
}
var newObj = {
...oldObj,
d:1,
a:2
}

Loopback Query


filter={
where:{
          gymId:"12345",
          endUTC:{lte:1000},
          endUTC:{gte:500},
          isDue:1,
          orderStatus:"new"
},
limit:20
}

{"where":
{
"gymId":"5c04e077d62b3e0a3ba4a918",
"or":[
{"startUTC":{"gte":1611072000}},
{"endUTC":{"lte":1616169600}}}
]
}