mysql - Terminating a callback in nodejs -


i new nodejs. using mysql node module. how use it:

var connection = mysql.createconnection({     host: 'localhost',     user: 'root',     password: '',     database: 'sample' });  connection.connect(function (err) {     if (!err) {         console.log("database connected ... \n\n");     } else {         console.log("error connecting database ... \n\n");     } });  var post  = {personid: 1, name: 'prachi', city: 'blore'}; var query = connection.query('insert persons set ?', post, function(error, result) {     if (error) {         console.log(error.message);     } else {         console.log('success');     } }); console.log(query.sql); 

this node code works functionally. in, adds data table. doesn't terminate. mistake making?

take closer @ official documentation, have close connection :

var mysql      = require('mysql'); var connection = mysql.createconnection({   host     : 'localhost',   user     : 'me',   password : 'secret' });  connection.connect();  connection.query('select 1 + 1 solution', function(err, rows, fields) {   if (err) throw err;    console.log('the solution is: ', rows[0].solution); });  connection.end(); 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -