node.js - TypeError: Cannot read property 'createConnection' of null when trying to connect node js to mysql for a zendesk app -


i'm new node, , i'm trying create zendesk app connects mysql when user inputs value. here's code app.js.

( function() {   return {      events: {       // framework events       'app.created':'checklocalstorage', // call 'checklocalstorage' function below        // request events (none)        // dom events       'keyup #input-value-id': function(event){ // user clicked 'enter'/'return' button store value in localstorage         if(event.keycode === 13) {            return this.processinputvalue();         }       },       'click .reset': 'resetvalue' // call 'resetvalue' function below     },      checklocalstorage: function () { // in localstorage if value present 'examplestring'         if (this.store('examplestring') === null) {            services.notify('localstorage value not set', 'alert', 500); // services notification            this.switchto('input_value'); // display input field user set value of localstorage          } else { // there value set 'examplestring' in localstorage            services.notify('localstorage value found', 'notice', 500); // services notification            var value = this.store('examplestring'); // instantiate variable 'value' set value in localstorage 'examplestring'            this.switchto('display_value', { // switch 'displayvalue' template             value: value // set handlebars.js placeholder 'value' equal variable 'value' above           });          }     },      processinputvalue: function() { // handle value entered input field in 'inputvalue' template       var examplestring = this.$('input#input-value-id').val(); // variable set value entered input field       this.store('examplestring', examplestring); // value of examplestring future use        examplestring = this.$('input#input-value-id').val(''); // empty input field - visual ux enhancement        services.notify('localstorage value set', 'notice', 500); // services notification        var value = this.store('examplestring');       this.switchto('display_value', {         value: value       });           var mysql = require('mysql');           var con = mysql.createconnection({               host: "localhost",               user: "root",               password: "waypass123"           });           con.connect(function(err) {               if (err) throw err;               console.log("connected!");               con.query("select * way0608.user_info", function (err, result, fields) {                   if (err) throw err;                     console.log(result);               });           });      },      resetvalue: function() {        this.store('examplestring', null); // set value of 'examplestring' in localstorage 'empty' variable (null)        services.notify('localstorage value reset', 'notice', 500); // services notification        this.switchto('input_value'); // display input field user set value of localstorage      }    };  }()); 

when run mysql portion of code in own js file, below, works fine.

var mysql = require('mysql');  var con = mysql.createconnection({   host: "localhost",   user: "root",   password: "pass" });  con.connect(function(err) {   if (err) throw err;   console.log("connected!");   con.query("select * test.user_info", function (err, result, fields) {     if (err) throw err;     console.log(result);   }); }); 

however, the typeerror while running app.js on zendesk. tested out running sample app on zendesk, worked fine. means sometime wrong mysql connection code.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -