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 ...
9.6K
1.7K
how to get client netmask using node.js ?NODEJS
Click to see more ...
5.9K
557
How to get client machine name and computer name with node.js?NODEJS
Click to see more ...
12.9K
440
how to get client local ip address using node.js ?NODEJS
Click to see more ...
2.8K
311
How to get client ip address using node.jsNODEJS
Click to see more ...
2.7K
271
How to combine node.js and jquery ?NODEJS
Click to see more ...
2K
247
how to detect tablet, iPad, iPhone, Android and Blackberry using nodejs ?NODEJS
Click to see more ...
2.3K
161
get client region using node.js ?NODEJS
Click to see more ...
2.3K
128
get real user ip address using node.js?NODEJS
Click to see more ...
1.9K
124
get server ip address from hostname nodejsNODEJS
Click to see more ...
3.6K
122