Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /usr/local/lib/node_modules/mysql/lib/protocol/Parser.js:77
- throw err; // Rethrow non-MySQL errors
- ^
- Error: write after end
- at writeAfterEnd (_stream_writable.js:133:12)
- at WriteStream.Writable.write (_stream_writable.js:181:5)
- at Query._callback (/var/www/html/JS/writeServerDB.js:69:13)
- at Query.Sequence.end
- (/usr/local/lib/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
- at Query._handleFinalResultPacket (/usr/local/lib/node_modules/mysql/lib/protocol/sequences/Query.js:144:8)
- at Query.EofPacket (/usr/local/lib/node_modules/mysql/lib/protocol/sequences/Query.js:128:8)
- at Protocol._parsePacket (/usr/local/lib/node_modules/mysql/lib/protocol/Protocol.js:280:23)
- at Parser.write (/usr/local/lib/node_modules/mysql/lib/protocol/Parser.js:73:12)
- at Protocol.write (/usr/local/lib/node_modules/mysql/lib/protocol/Protocol.js:39:16)
- at Socket.<anonymous> (/usr/local/lib/node_modules/mysql/lib/Connection.js:96:28)
- var mysql = require('mysql');
- var con = mysql.createConnection({
- host: "some numbers",
- user: "user",
- password: "password",
- databse: "database"
- });
- //shows success or failure in the connection
- con.connect(function(err){
- if(err){
- console.log('Error connecting to DB');
- return;
- }
- console.log('Connection Established');
- })
- //begins the read/write connection
- var fs = require('fs');
- var wstream = fs.createWriteStream('/home/document1');
- var content = "";
- //executes the given query and exports it to the console
- con.query("SELECT * FROM database.table WHERE ID < 20", function(err, rows, fields){
- if(!err){
- for(var i = 0; i < rows.length; i++){
- content = content + "{a lot of data taken from mysql connection} <br/>";
- }
- //removes the last comma
- //content = content.substring(0, content.length - 1);
- wstream.write(content);
- wstream.on('finish', function(){
- console.log('File has been written');
- })
- console.log(content);
- } else{
- console.log('Error while performing query');
- }
- })
- con.end(function(err){
- //The connection is terminated gracefully
- //Ensures all previously enqueued queries are still
- //before sending a COM_QUIT to the mysql server.
- })
- wstream.end();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement