Streaming data from oracle db to browser with node.js2019 Community Moderator ElectionGet list of all tables in Oracle?How do I debug Node.js applications?How do I get started with Node.jsWriting files in Node.jsHow do I pass command line arguments to a Node.js program?Check synchronously if file/directory exists in Node.jsRead environment variables in Node.jsHow to decide when to use Node.js?How to exit in Node.jsWhat is the purpose of Node.js module.exports and how do you use it?
What problems would a superhuman have whose skin is constantly hot?
Can one live in the U.S. and not use a credit card?
Signed and unsigned numbers
How to save the initial startup configuration in IOS XR?
What official source details what an Empire citizen knows of WFRP's monsters?
Shifting between bemols (flats) and diesis (sharps)in the key signature
Is this Paypal Github SDK reference really a dangerous site?
What are some noteworthy "mic-drop" moments in math?
Is there a difference between equilibrium and steady state?
How are showroom/display vehicles prepared?
What would be the most expensive material to an intergalactic society?
PTIJ: Should I kill my computer after installing software?
How to secure an aircraft at a transient parking space?
What are the practical Opportunty Attack values for a bugbear, holding a reach weapon, with Polearm Mastery?
What was the Kree's motivation in Captain Marvel?
School performs periodic password audits. Is my password compromised?
Why the color red for the Republican Party
Does "Until when" sound natural for native speakers?
List elements digit difference sort
In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?
Why does liquid water form when we exhale on a mirror?
Was it really inappropriate to write a pull request for the company I interviewed with?
How can I get players to stop ignoring or overlooking the plot hooks I'm giving them?
Professor expects me to attend a conference, I can't afford even with 50% funding
Streaming data from oracle db to browser with node.js
2019 Community Moderator ElectionGet list of all tables in Oracle?How do I debug Node.js applications?How do I get started with Node.jsWriting files in Node.jsHow do I pass command line arguments to a Node.js program?Check synchronously if file/directory exists in Node.jsRead environment variables in Node.jsHow to decide when to use Node.js?How to exit in Node.jsWhat is the purpose of Node.js module.exports and how do you use it?
I am learning node.js and database. I am trying to stream heavy data about 7,700,000 rows and 96 columns from oracle to client. Later i use that data for virtual table. But in client it is showing only one row and then in node command error is displaying "Cannot set headers after they are sent to the client". How to stream data in client. Please help
var oracledb = require('oracledb');
const cors = require('cors');
var express = require('express');
var app = express();
app.use(cors());
oracledb.outFormat = oracledb.ARRAY;
oracledb.getConnection(
user: 'user',
password: 'password',
connectString: 'some string'
,
(err, connection) =>
if (err)
console.error(err.message);
return;
var rowsProcessed = 0;
var startTime = Date.now();
var dataSize = 0;
var stream = connection.queryStream(
'SELECT * FROM table',
);
// stream.on('data', function (data)
// rowsProcessed++;
// // console.log(JSON.stringify(data));
// // console.log(data);
// dataSize = dataSize + data.length;
// // oracleData.push(data);
// // console.log("pushing");
// // console.log(oracleData);
// // app.get('/data', (req, res) =>
// // res.send(data);
// // )
// // console.log(data);
// );
app.get('/data', (req, res) =>
stream.on('data', (data) =>
rowsProcessed++;
dataSize = dataSize + data.length;
res.send(JSON.stringify(data));
)
)
stream.on('end', function ()
var t = ((Date.now() - startTime) / 1000);
console.log('queryStream(): rows: ' + rowsProcessed +
', seconds: ' + t);
// console.log(dataSize + ' bytes');
connection.close(
function (err)
if (err)
console.error(err.message);
else
console.log("connection closed")
)
)
);
app.listen(5000, () =>
console.log('Listening at 5000')
)
I tried using above approach. But it is failing. How can I achieve the output?
The browser is freezing if I output entire data at single time that's why I am trying to use streaming and in the node command prompt it is displaying out of memory if I load entire data at single time.
Thank you.
node.js oracle
add a comment |
I am learning node.js and database. I am trying to stream heavy data about 7,700,000 rows and 96 columns from oracle to client. Later i use that data for virtual table. But in client it is showing only one row and then in node command error is displaying "Cannot set headers after they are sent to the client". How to stream data in client. Please help
var oracledb = require('oracledb');
const cors = require('cors');
var express = require('express');
var app = express();
app.use(cors());
oracledb.outFormat = oracledb.ARRAY;
oracledb.getConnection(
user: 'user',
password: 'password',
connectString: 'some string'
,
(err, connection) =>
if (err)
console.error(err.message);
return;
var rowsProcessed = 0;
var startTime = Date.now();
var dataSize = 0;
var stream = connection.queryStream(
'SELECT * FROM table',
);
// stream.on('data', function (data)
// rowsProcessed++;
// // console.log(JSON.stringify(data));
// // console.log(data);
// dataSize = dataSize + data.length;
// // oracleData.push(data);
// // console.log("pushing");
// // console.log(oracleData);
// // app.get('/data', (req, res) =>
// // res.send(data);
// // )
// // console.log(data);
// );
app.get('/data', (req, res) =>
stream.on('data', (data) =>
rowsProcessed++;
dataSize = dataSize + data.length;
res.send(JSON.stringify(data));
)
)
stream.on('end', function ()
var t = ((Date.now() - startTime) / 1000);
console.log('queryStream(): rows: ' + rowsProcessed +
', seconds: ' + t);
// console.log(dataSize + ' bytes');
connection.close(
function (err)
if (err)
console.error(err.message);
else
console.log("connection closed")
)
)
);
app.listen(5000, () =>
console.log('Listening at 5000')
)
I tried using above approach. But it is failing. How can I achieve the output?
The browser is freezing if I output entire data at single time that's why I am trying to use streaming and in the node command prompt it is displaying out of memory if I load entire data at single time.
Thank you.
node.js oracle
add a comment |
I am learning node.js and database. I am trying to stream heavy data about 7,700,000 rows and 96 columns from oracle to client. Later i use that data for virtual table. But in client it is showing only one row and then in node command error is displaying "Cannot set headers after they are sent to the client". How to stream data in client. Please help
var oracledb = require('oracledb');
const cors = require('cors');
var express = require('express');
var app = express();
app.use(cors());
oracledb.outFormat = oracledb.ARRAY;
oracledb.getConnection(
user: 'user',
password: 'password',
connectString: 'some string'
,
(err, connection) =>
if (err)
console.error(err.message);
return;
var rowsProcessed = 0;
var startTime = Date.now();
var dataSize = 0;
var stream = connection.queryStream(
'SELECT * FROM table',
);
// stream.on('data', function (data)
// rowsProcessed++;
// // console.log(JSON.stringify(data));
// // console.log(data);
// dataSize = dataSize + data.length;
// // oracleData.push(data);
// // console.log("pushing");
// // console.log(oracleData);
// // app.get('/data', (req, res) =>
// // res.send(data);
// // )
// // console.log(data);
// );
app.get('/data', (req, res) =>
stream.on('data', (data) =>
rowsProcessed++;
dataSize = dataSize + data.length;
res.send(JSON.stringify(data));
)
)
stream.on('end', function ()
var t = ((Date.now() - startTime) / 1000);
console.log('queryStream(): rows: ' + rowsProcessed +
', seconds: ' + t);
// console.log(dataSize + ' bytes');
connection.close(
function (err)
if (err)
console.error(err.message);
else
console.log("connection closed")
)
)
);
app.listen(5000, () =>
console.log('Listening at 5000')
)
I tried using above approach. But it is failing. How can I achieve the output?
The browser is freezing if I output entire data at single time that's why I am trying to use streaming and in the node command prompt it is displaying out of memory if I load entire data at single time.
Thank you.
node.js oracle
I am learning node.js and database. I am trying to stream heavy data about 7,700,000 rows and 96 columns from oracle to client. Later i use that data for virtual table. But in client it is showing only one row and then in node command error is displaying "Cannot set headers after they are sent to the client". How to stream data in client. Please help
var oracledb = require('oracledb');
const cors = require('cors');
var express = require('express');
var app = express();
app.use(cors());
oracledb.outFormat = oracledb.ARRAY;
oracledb.getConnection(
user: 'user',
password: 'password',
connectString: 'some string'
,
(err, connection) =>
if (err)
console.error(err.message);
return;
var rowsProcessed = 0;
var startTime = Date.now();
var dataSize = 0;
var stream = connection.queryStream(
'SELECT * FROM table',
);
// stream.on('data', function (data)
// rowsProcessed++;
// // console.log(JSON.stringify(data));
// // console.log(data);
// dataSize = dataSize + data.length;
// // oracleData.push(data);
// // console.log("pushing");
// // console.log(oracleData);
// // app.get('/data', (req, res) =>
// // res.send(data);
// // )
// // console.log(data);
// );
app.get('/data', (req, res) =>
stream.on('data', (data) =>
rowsProcessed++;
dataSize = dataSize + data.length;
res.send(JSON.stringify(data));
)
)
stream.on('end', function ()
var t = ((Date.now() - startTime) / 1000);
console.log('queryStream(): rows: ' + rowsProcessed +
', seconds: ' + t);
// console.log(dataSize + ' bytes');
connection.close(
function (err)
if (err)
console.error(err.message);
else
console.log("connection closed")
)
)
);
app.listen(5000, () =>
console.log('Listening at 5000')
)
I tried using above approach. But it is failing. How can I achieve the output?
The browser is freezing if I output entire data at single time that's why I am trying to use streaming and in the node command prompt it is displaying out of memory if I load entire data at single time.
Thank you.
node.js oracle
node.js oracle
edited Mar 7 at 11:28
Kiran Villa
asked Mar 7 at 6:24
Kiran VillaKiran Villa
433
433
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The first thing you'll want to do is organize your app a little better. Separation of concerns is important, you should have a connection pool, etc. Have a look at this series for some ideas: https://jsao.io/2018/03/creating-a-rest-api-with-node-js-and-oracle-database/
Once you get the organization figured out, incorporate this example of streaming a large result set out.
const oracledb = require('oracledb');
async function get(req, res, next)
try
const conn = await oracledb.getConnection();
const stream = await conn.queryStream('select * from employees', [], outFormat: oracledb.OBJECT);
res.writeHead(200, 'Content-Type': 'application/json');
res.write('[');
stream.on('data', (row) =>
res.write(JSON.stringify(row));
res.write(',');
);
stream.on('end', () =>
res.end(']');
);
stream.on('close', async () =>
try
await conn.close();
catch (err)
console.log(err);
);
stream.on('error', async (err) =>
next(err);
try
await conn.close();
catch (err)
console.log(err);
);
catch (err)
next(err);
module.exports.get = get;
If you find you're doing this a lot, simplify things by creating a reusable transform stream:
const oracledb = require('oracledb');
const Transform = require('stream');
class ToJSONArray extends Transform
constructor()
super(objectMode: true);
this.push('[');
_transform (row, encoding, callback)
if (this._prevRow)
this.push(JSON.stringify(this._prevRow));
this.push(',');
this._prevRow = row;
callback(null);
_flush (done)
if (this._prevRow)
this.push(JSON.stringify(this._prevRow));
this.push(']');
delete this._prevRow;
done();
async function get(req, res, next)
try
const toJSONArray = new ToJSONArray();
const conn = await oracledb.getConnection();
const stream = await conn.queryStream('select * from employees', [], outFormat: oracledb.OBJECT);
res.writeHead(200, 'Content-Type': 'application/json');
stream.pipe(toJSONArray).pipe(res);
stream.on('close', async () =>
try
await conn.close();
catch (err)
console.log(err);
);
stream.on('error', async (err) =>
next(err);
try
await conn.close();
catch (err)
console.log(err);
);
catch (err)
next(err);
module.exports.get = get;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037309%2fstreaming-data-from-oracle-db-to-browser-with-node-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The first thing you'll want to do is organize your app a little better. Separation of concerns is important, you should have a connection pool, etc. Have a look at this series for some ideas: https://jsao.io/2018/03/creating-a-rest-api-with-node-js-and-oracle-database/
Once you get the organization figured out, incorporate this example of streaming a large result set out.
const oracledb = require('oracledb');
async function get(req, res, next)
try
const conn = await oracledb.getConnection();
const stream = await conn.queryStream('select * from employees', [], outFormat: oracledb.OBJECT);
res.writeHead(200, 'Content-Type': 'application/json');
res.write('[');
stream.on('data', (row) =>
res.write(JSON.stringify(row));
res.write(',');
);
stream.on('end', () =>
res.end(']');
);
stream.on('close', async () =>
try
await conn.close();
catch (err)
console.log(err);
);
stream.on('error', async (err) =>
next(err);
try
await conn.close();
catch (err)
console.log(err);
);
catch (err)
next(err);
module.exports.get = get;
If you find you're doing this a lot, simplify things by creating a reusable transform stream:
const oracledb = require('oracledb');
const Transform = require('stream');
class ToJSONArray extends Transform
constructor()
super(objectMode: true);
this.push('[');
_transform (row, encoding, callback)
if (this._prevRow)
this.push(JSON.stringify(this._prevRow));
this.push(',');
this._prevRow = row;
callback(null);
_flush (done)
if (this._prevRow)
this.push(JSON.stringify(this._prevRow));
this.push(']');
delete this._prevRow;
done();
async function get(req, res, next)
try
const toJSONArray = new ToJSONArray();
const conn = await oracledb.getConnection();
const stream = await conn.queryStream('select * from employees', [], outFormat: oracledb.OBJECT);
res.writeHead(200, 'Content-Type': 'application/json');
stream.pipe(toJSONArray).pipe(res);
stream.on('close', async () =>
try
await conn.close();
catch (err)
console.log(err);
);
stream.on('error', async (err) =>
next(err);
try
await conn.close();
catch (err)
console.log(err);
);
catch (err)
next(err);
module.exports.get = get;
add a comment |
The first thing you'll want to do is organize your app a little better. Separation of concerns is important, you should have a connection pool, etc. Have a look at this series for some ideas: https://jsao.io/2018/03/creating-a-rest-api-with-node-js-and-oracle-database/
Once you get the organization figured out, incorporate this example of streaming a large result set out.
const oracledb = require('oracledb');
async function get(req, res, next)
try
const conn = await oracledb.getConnection();
const stream = await conn.queryStream('select * from employees', [], outFormat: oracledb.OBJECT);
res.writeHead(200, 'Content-Type': 'application/json');
res.write('[');
stream.on('data', (row) =>
res.write(JSON.stringify(row));
res.write(',');
);
stream.on('end', () =>
res.end(']');
);
stream.on('close', async () =>
try
await conn.close();
catch (err)
console.log(err);
);
stream.on('error', async (err) =>
next(err);
try
await conn.close();
catch (err)
console.log(err);
);
catch (err)
next(err);
module.exports.get = get;
If you find you're doing this a lot, simplify things by creating a reusable transform stream:
const oracledb = require('oracledb');
const Transform = require('stream');
class ToJSONArray extends Transform
constructor()
super(objectMode: true);
this.push('[');
_transform (row, encoding, callback)
if (this._prevRow)
this.push(JSON.stringify(this._prevRow));
this.push(',');
this._prevRow = row;
callback(null);
_flush (done)
if (this._prevRow)
this.push(JSON.stringify(this._prevRow));
this.push(']');
delete this._prevRow;
done();
async function get(req, res, next)
try
const toJSONArray = new ToJSONArray();
const conn = await oracledb.getConnection();
const stream = await conn.queryStream('select * from employees', [], outFormat: oracledb.OBJECT);
res.writeHead(200, 'Content-Type': 'application/json');
stream.pipe(toJSONArray).pipe(res);
stream.on('close', async () =>
try
await conn.close();
catch (err)
console.log(err);
);
stream.on('error', async (err) =>
next(err);
try
await conn.close();
catch (err)
console.log(err);
);
catch (err)
next(err);
module.exports.get = get;
add a comment |
The first thing you'll want to do is organize your app a little better. Separation of concerns is important, you should have a connection pool, etc. Have a look at this series for some ideas: https://jsao.io/2018/03/creating-a-rest-api-with-node-js-and-oracle-database/
Once you get the organization figured out, incorporate this example of streaming a large result set out.
const oracledb = require('oracledb');
async function get(req, res, next)
try
const conn = await oracledb.getConnection();
const stream = await conn.queryStream('select * from employees', [], outFormat: oracledb.OBJECT);
res.writeHead(200, 'Content-Type': 'application/json');
res.write('[');
stream.on('data', (row) =>
res.write(JSON.stringify(row));
res.write(',');
);
stream.on('end', () =>
res.end(']');
);
stream.on('close', async () =>
try
await conn.close();
catch (err)
console.log(err);
);
stream.on('error', async (err) =>
next(err);
try
await conn.close();
catch (err)
console.log(err);
);
catch (err)
next(err);
module.exports.get = get;
If you find you're doing this a lot, simplify things by creating a reusable transform stream:
const oracledb = require('oracledb');
const Transform = require('stream');
class ToJSONArray extends Transform
constructor()
super(objectMode: true);
this.push('[');
_transform (row, encoding, callback)
if (this._prevRow)
this.push(JSON.stringify(this._prevRow));
this.push(',');
this._prevRow = row;
callback(null);
_flush (done)
if (this._prevRow)
this.push(JSON.stringify(this._prevRow));
this.push(']');
delete this._prevRow;
done();
async function get(req, res, next)
try
const toJSONArray = new ToJSONArray();
const conn = await oracledb.getConnection();
const stream = await conn.queryStream('select * from employees', [], outFormat: oracledb.OBJECT);
res.writeHead(200, 'Content-Type': 'application/json');
stream.pipe(toJSONArray).pipe(res);
stream.on('close', async () =>
try
await conn.close();
catch (err)
console.log(err);
);
stream.on('error', async (err) =>
next(err);
try
await conn.close();
catch (err)
console.log(err);
);
catch (err)
next(err);
module.exports.get = get;
The first thing you'll want to do is organize your app a little better. Separation of concerns is important, you should have a connection pool, etc. Have a look at this series for some ideas: https://jsao.io/2018/03/creating-a-rest-api-with-node-js-and-oracle-database/
Once you get the organization figured out, incorporate this example of streaming a large result set out.
const oracledb = require('oracledb');
async function get(req, res, next)
try
const conn = await oracledb.getConnection();
const stream = await conn.queryStream('select * from employees', [], outFormat: oracledb.OBJECT);
res.writeHead(200, 'Content-Type': 'application/json');
res.write('[');
stream.on('data', (row) =>
res.write(JSON.stringify(row));
res.write(',');
);
stream.on('end', () =>
res.end(']');
);
stream.on('close', async () =>
try
await conn.close();
catch (err)
console.log(err);
);
stream.on('error', async (err) =>
next(err);
try
await conn.close();
catch (err)
console.log(err);
);
catch (err)
next(err);
module.exports.get = get;
If you find you're doing this a lot, simplify things by creating a reusable transform stream:
const oracledb = require('oracledb');
const Transform = require('stream');
class ToJSONArray extends Transform
constructor()
super(objectMode: true);
this.push('[');
_transform (row, encoding, callback)
if (this._prevRow)
this.push(JSON.stringify(this._prevRow));
this.push(',');
this._prevRow = row;
callback(null);
_flush (done)
if (this._prevRow)
this.push(JSON.stringify(this._prevRow));
this.push(']');
delete this._prevRow;
done();
async function get(req, res, next)
try
const toJSONArray = new ToJSONArray();
const conn = await oracledb.getConnection();
const stream = await conn.queryStream('select * from employees', [], outFormat: oracledb.OBJECT);
res.writeHead(200, 'Content-Type': 'application/json');
stream.pipe(toJSONArray).pipe(res);
stream.on('close', async () =>
try
await conn.close();
catch (err)
console.log(err);
);
stream.on('error', async (err) =>
next(err);
try
await conn.close();
catch (err)
console.log(err);
);
catch (err)
next(err);
module.exports.get = get;
answered Mar 7 at 14:07
Dan McGhanDan McGhan
1,158186
1,158186
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037309%2fstreaming-data-from-oracle-db-to-browser-with-node-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown