const result = [ { // This is sample data BUT there can be multiple objects "name": "object1", "id": "1", "timeseriesData": [ [ 1548979200000, // epoc timestamp 325.3 // value in number ], [ 1548979260000, 325.8 ], [ 1548979320000, 324.2 ], [ 1548979380000, 323.7 ], [ 1548979440000, 322.3 ], [ 1548979500000, 322 ] ] }, { "name": "object2", "id": "2", "timeseriesData": [ [ 1548989200000, 625.3 ], [ 1548989260000, 625.8 ], [ 1548989320000, 624.2 ], [ 1548989380000, 623.7 ], [ 1548989440000, 622.3 ], [ 1548989500000, 622 ] ] } ] const splitInChunks = (sizeInBytes) => // Don't think this is helping to create proper chunks (buffer) => { console.log(buffer); const size = Buffer.byteLength(buffer.buffer); let start = 0; let end = sizeInBytes; const chunks = []; do { chunks.push(buffer.subarray(start, end)); start += sizeInBytes; end += sizeInBytes; } while (start < size); return chunks; }; const chunks = splitInChunks(32)(Buffer.from(JSON.stringify(result))); console.log("chunks length", chunks.length) console.log('chunks[0]-', chunks[0]) console.log(JSON.parse(Buffer.concat(chunks))) const converted = chunks.map(c=> Buffer.from(JSON.stringify({requestId:"123", buf: c}))); console.log("converted length", converted.length) const result1 = []; for (let con of converted) { const eachChunk = JSON.parse(con); result1.push(eachChunk.buf) } console.log('result1', result1) console.log(JSON.parse(Buffer.concat(result1)))
Write, Run & Share NodeJS code online using OneCompiler's NodeJS online compiler for free. It's one of the robust, feature-rich online compilers for NodeJS language,running on the latest LTS version NodeJS 16.14.2. Getting started with the OneCompiler's NodeJS editor is easy and fast. The editor shows sample boilerplate code when you choose language as NodeJS and start coding. You can provide the dependencies in package.json
.
Node.js is a free and open-source server environment. Node.js is very popular in recent times and a large number of companies like Microsoft, Paypal, Uber, Yahoo, General Electric and many others are using Node.js.
Google chrome's javascript engine V8
and is pretty fast.Asynchronous
, event-driven
and works on single-thread model
thus eliminating the dis-advantages of multi-thread model.Express is one of the most popular web application framework in the NodeJS echosystem.
let moment = require('moment');
console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));
const _ = require("lodash");
let colors = ['blue', 'green', 'yellow', 'red'];
let firstElement = _.first(colors);
let lastElement = _.last(colors);
console.log(`First element: ${firstElement}`);
console.log(`Last element: ${lastElement}`);
Following are the libraries supported by OneCompiler's NodeJS compiler.