javascript - writestream and express for json object? -
I should be out of depth, but I really want something to work I think a write / read stream Both issues will solve, but I have not understood the syntax or what is necessary to do the work. I read the booklet and thought that I understand some of the basic things, but when I try to apply it in my situation it starts breaking down.
Currently, this is the root cause of my knowledge.
read the function (x) {console.log ("read" + x [6] + "and top half sent in the cache"); Jf.readFile ("Loadedport / Top" + X [6], 'UTF 8', Function (Error, Data) {resT = Data}); };
I am using the Jsonfile plugin for the node, which basically reduces fs.write and instead of typing, write and read the blocks for fs.write and Makes easy to read
Anyway, I want to implement a stream here but I am not sure what will happen to my express end and how to get the object.
I suppose because its a stream does not express anything object until it does not receive? Or should I also write a callback to make sure that when my function is called, before the express ajax sends the object off to complete the request?
app.get ('/: report / top', function (rick, race) {readDataTop (global [req.params.report]); res.header ("content-type" , "App / Jason; Charset = UTF-8"); res header ("cache-control", "max-age = 3600"); res.json (resT); resT = 0;});
I hope that if I change the reading part into one stream, then it will get two problems. Sometimes issue of obtaining fair json files when the browser calls AJAX due to the reading speed of large Jason objects. (This may need to solve the callback problem, but a stream should make it more consistent).
Then the second thing is that when I load this node app, I had to disconnect the browser from the target DB side with my DB, so the node acts as DB by reading and writing . This is due to an old SQL Server which is already being bombarded with too many requests (stale data is not an issue).
Is there any help on syntax?
Is there any tutorial I can do a response piping in a writing stream? (The mssql node I used to put a SQL response in an object and should be in JSON format).
function getDataTop (x) {var connection = new sql.connection (config, function) {var request = new sql.Request (connection); Request.query (error [top], jf.writeFile ("loadport / top" + x [6], toppers, function (mistake) {if (error) {console.log (err); } Else {console.log (x [6] + "Half of the above was saved!");}});});}); };
Your problem is that you do not wait to load before sending the file Are the response. Use callback:
Reading functionDatabase (X, CB) {console.log ('Read' + [[6] + 'and Cash-leveled Top Half'); Jf.readFile ('Loadedport / Top' + x [6], 'UTF 8', CB); }; // ... app.get ('/: report / top', function (req, res) {// You should actually use such global ... readDataTop (global [req.params.report] , Setting function (Err, obj) {// content type automatically requires cache data here-in-memory by `res.json ()` // and before checking for its existence // readDataTop Before `res.header ('cache-control', 'max-age = 3600'); res.json (obj);});});
Comments
Post a Comment