mysql - Exiting a node script after sending Push Notifications -


the code long question elementary.

const webpush = require('web-push'); const argv = require('yargs').argv; const mysql = require('mysql'); const config = require('./../config.json'); const con = mysql.createconnection({   host: config.pushnotifications.host,   user: config.pushnotifications.user,   password: config.pushnotifications.password,   database: config.pushnotifications.database });  con.connect(function(err) {});  return sendnotif();  function sendnotif() {   const type = argv.type;   const datatosend = {     "title": argv.title,     "message": argv.message   };    return getsubscriptions()     .then(function(subscriptions) {       let promisechain = promise.resolve();        (let = 0; < subscriptions.length; i++) {         let subscription = subscriptions[i];          let pref = subscription.preferences.split('');          if (pref[type - 1] == 1) {           promisechain = promisechain.then(() => {             return triggerpushmsg(subscription, json.stringify(datatosend));           });         }       }     })     .catch(function(err) {       throw new error(err);     }); }   function triggerpushmsg(subscription, datatosend) {   return webpush.sendnotification(subscription, datatosend)     .catch((err) => {       if (err.statuscode === 410) {         return deletesubscriptionfromdatabase(subscription.endpoint);       } else {         log.warn('subscription no longer valid: ', err);       }     }); }  function deletesubscriptionfromdatabase(endpoint) {   let sql = 'delete subscriptions endpoint = ?';    return new promise(function(resolve, reject) {     con.query(sql, [endpoint], function(err, result) {       if (err) {         throw reject(err);       }       log.debug('deleted database. endpoint: ', endpoint);       resolve(true);     });   }); }  function getsubscriptions() {   let sql = 'select * subscriptions';    return new promise(function(resolve, reject) {     con.query(sql, function(err, result) {       if (err) {         throw reject(err);       }       resolve(result);     });   }); } 

this code fetches subscriptions mysql database , sends notifications it. have skipped vapid keys initialisation part have done correctly in program runs fine , notifications delivered. problem is, once run using command-

node test/notification-trigger.js --type <type> --title "<title>" --message "<message>" 

the program not terminate automatically.

what needs changed here? in anticipation.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -