Hi,
I have requriement to return array from node js I want to retrun result
like below. Any help will be appreciated.
[ 'SUCCESS','0000','Msg','DB connection was successful']
Calling file
var fn = require("./sql.js");
var mysql = require("mysql");
var con = mysql.createConnection({
host: "localhost",
user: "",
password: ""
});
//console.log(fn.connectToDB(con));
console.log('final output'+fn.connectToDB(con));
======================================================
Fuctions.js
module.exports = {connectToDB};
var mysql = require("mysql");
// Generic JSON Array for response Status, Number of rows affected, Type,
Data
var result = ['adf']; //
'Success','1','Data','{"Email":'[email protected]',"Location":'Chicago'}
// First you need to create a connection to the db
var con = mysql.createConnection({
host: "localhost",
user: "",
password: ""
});
var callback = function (response){
console.log(response);
};
function connectToDB(con){ // pass connection parameters as arg
con.connect(function(err){
if(err){
console.log('Error connecting to Db');
result.push('ERROR');
result.push('5001'); // Error connecting to DB
result.push('Msg');
result.push('Error connecting to DB');
//return result;
}
console.log('Connection established');
result.push('SUCCESS');
result.push('0000'); // code for success
result.push('Msg');
result.push('DB connection was successful');
// console.log(result);
//return result;
});
con.end(function(err) { console.log(result);
});
// The connection is terminated gracefully
// Ensures all previously enqueued queries are still
// before sending a COM_QUIT packet to the MySQL server.
console.log(result);
//return result;
//return result;
}
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/4dfcc5ff-640b-4c6b-a636-4b76581f7289%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.