Welcome aboard! We are happy you are here and wish you good net-raft!
// the structure of MYTABLE
// Name Age
// Jack 25
// John 33
// Steve 31
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "xxx",
database: "xxx"
});
con.connect(function(err) {
if (err) throw err;
console.log("the connection is open!");
con.query("SELECT * FROM MYTABLE", function (err, result) {
if (err) throw err;
var fs = require('fs');
var writeStream = fs.createWriteStream("file.xls");
var header = "Name"+" "+"Age"+"
";
var row1 = "";
for (y = 0; y < result.length; y++) {
row1 = row1 + result[y].name + " " + result[y].age + "
";
}
writeStream.write(header + row1);
writeStream.close();
if (!writeStream )
console.log('something went wrong!');
else
console.log('the excel successfully created!"');
});
con.end();
});
The most helpful NODEJS solutions
get user ipNODEJS Click to see more ... 7.6K 1.7K