Using the dashboard node in Node-RED to showcase MySQL query results

Beginner inquiry: I am exploring node-red and believe it could serve as a valuable introduction to node.js (and javascript in general). However, I've hit a roadblock.

I have built a flow that executes a basic query on a mysql database. While I'm receiving the results, I am having trouble parsing them effectively. It seems like the results are returned in an array format, but I'm unsure how to access and manipulate this array within a function. Below is the data sent from the mysql node:

[
  { "at_time": "2017-03-27T18:33:46.000Z", "event": "gone_to_bed" },
  { "at_time": "2017-03-27T22:14:02.000Z", "event": "woke_up" },
  { "at_time": "2017-03-27T22:14:12.000Z", "event": "food" },
  { "at_time": "2017-03-28T00:13:42.000Z", "event": "woke_up" },
  { "at_time": "2017-03-28T03:50:15.000Z", "event": "woke_up" },
  { "at_time": "2017-03-28T05:12:33.000Z", "event": "woke_up" },
  { "at_time": "2017-03-28T05:12:38.000Z", "event": "food" },
  { "at_time": "2017-03-28T06:56:29.000Z", "event": "up_for_day" },
  { "at_time": "2017-03-28T18:08:49.000Z", "event": "gone_to_bed" },
  { "at_time": "2017-03-28T18:32:48.000Z", "event": "woke_up" }
]

Appreciate any guidance!

Answer №1

When it comes to JavaScript arrays, there is a wealth of functions at your disposal to assist in manipulating their content. Providing a concise answer without more specific information on your objectives would be challenging.

Node-RED, being constructed using JavaScript, also relies on similar principles with its Function node.

If the array is being received in your Function as msg.payload, you can access individual elements using the syntax below:

var firstElement = msg.payload[0];
var secondElement = msg.payload[1];

Each element within the array seems to be a JavaScript object containing key/value pairs. To extract these values, use the following syntax:

var first_at_time = firstElement.at_time;
var first_event = firstElement.event;

These are fundamental JavaScript operations, and there are various resources available to guide you through them, such as: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Arrays

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Excruciatingly tardy performance from Node, Apollo, and Sequelize (over 7 seconds)

Although I'm more comfortable with Laravel, I am experiencing a delay of approximately 7.2 seconds when running a single query in Apollo Server for around 300 items. The resolver code provided below seems to be fairly straightforward and only involves ...

Adjust the visual presentation based on the chosen option at the top of a column JQchart

Can anyone offer assistance with creating three radio button fields that will display yearly, monthly, or weekly data on a column chart? I have searched through numerous examples in JQchart but haven't found one for this specific scenario. Are there o ...

Incorporating an HTML header into a QNetworkReply

I have implemented a customized QNetworkAccessManager and subclassed QNetworkReply to handle unique AJAX requests from a JavaScript application. It is functioning mostly as expected, but I have encountered an issue where my network replies seem to be missi ...

What is the process for invoking an External Javascript Firestore function within a Typescript file?

Trying to figure out how to integrate a Firestore trigger written in an external JavaScript file (notifyNewMessage.js) into my TypeScript file (index.ts) using Node.js for Cloud functions. Both files are located in the same directory: https://i.stack.imgu ...

Updating votes on the client side in WebForms can be achieved by following these steps

I am currently working on implementing a voting system similar to Stack Overflow's. Each item has a vote button next to it, and I have it functioning server side causing a delay in reloading the data. Here is the current flow: Clicking the vote butt ...

Mapping Longitude and Latitude with TopoJSON and D3

Currently utilizing the UK Geo JSON found at this link to generate a UK SVG Map. The goal is to plot longitude and latitude points onto this map. The GeometryCollection place is being added to the map in the following manner: data.objects.places = { ...

What is the jQuery Autocomplete syntax like?

Though my experience with jQuery is limited, I have successfully implemented Autocomplete code that highlights the search characters in the dropdown rows: .autocomplete({ delay: 500, minLength: 0, source: function(request, response) { ...

cordova and nodejs causing a communication problem

As a UI front end Developer, my expertise lies in user interface design rather than server side and port connections. I have successfully created a node server.js file that looks like this: var app = express(); var http = require('http').Server( ...

Using the datepicker class in an input field causes issues with the functionality of the bootstrap datepicker, specifically the autoclose, endDate, and startDate properties do not function as

I'm facing an issue with my code when I add the datepicker to the input field's class. JS $(document).ready(function () { $("#ActionDateInput").datepicker({ autoclose: true, endDate: new Date() }); }); HTML <input type= ...

Encountering a WriteableDraft error in Redux when using Type Definitions in TypeScript

I'm facing a type Error that's confusing me This is the state type: export type Foo = { animals: { dogs?: Dogs[], cats?: Cats[], fishs?: Fishs[] }, animalQueue: (Dogs | Cats | Fishs)[] } Now, in a reducer I&a ...

The minimum and maximum validation functions are triggered when I am not utilizing array controls, but they do not seem to work when I use array controls

Take a look at the stack blitz example where min and max validation is triggered: https://stackblitz.com/edit/angular-mat-form-field-icrmfw However, in the following stack blitz with an array of the same controls, the validation does not seem to be worki ...

What steps should be taken to refresh a page following an AJAX file upload?

I need some help creating a progress bar to track file uploads on my website. Here's what I have so far: HTML: <form action="upload/files.php" method="post" enctype="multipart/form-data" id="frmUpload"> <input type="file" name="upfile" ...

What is the best way to reindex dynamically added rows in jQuery?

I've been searching everywhere, but I can't seem to find the solution to my problem. I have a table where rows are dynamically added based on an index. So, when I click on a link in row 5, I want to add a new row at index 6. The issue arises when ...

I encountered some problems with conflicting Angular dependencies, so I decided to delete the node_modules folder

An error has occurred: The module 'H:\All_Files\Scripts\Angular\example\node_modules\source-map\source-map.js' could not be found. Please ensure that the package.json file contains a correct "main" entry. ...

`How can I effectively manage errors within an ASP.NET HTTP handler?`

I wrote an Httphandler in asp.net that is responsible for returning a file. Within the code, I have implemented Response.AddHeader("Content-Disposition", "attachment; filename=somefile.ext"); to ensure that the page URL remains unchanged. However, when an ...

Could someone assist me in understanding why VScode is displaying an error stating it cannot locate a module?

node:internal/modules/cjs/loader:1051 throw err; ^ Error: The module '/Users/ben/Desktop/GA/unit2/week5/GA_Project_2/QuotaQuest/index.js' cannot be found. at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15) at Modul ...

The ng-change directive is used on a dropdown to modify the styling of another HTML element

I need the icon to the left of the input in my HTML form to change based on whether the user selects male or female. However, I am facing an issue where when switching from nothing to female, the icon does not update immediately (even though the ng-change ...

Utilize fetch API in React to streamline API responses by filtering out specific fields

I have received an API response with various fields, but I only need to extract the description and placeLocation. results: [{placeId: "BHLLC", placeLocation: "BUFR", locationType: "BUFR",…},…] 0: {placeId: "BHLL ...

Tips for keeping an item consistently at the top in a React Native application

Within my flatlist, I have a card that is displayed when a user makes a post. However, the card currently appears randomly on the screen. I would like the card to always be rendered at the top of the screen whenever a user makes a post, similar to how it ...

Tips for sorting on an ANTD table with a JSON array column instead of a string

I am facing an issue with filtering and searching in an antd table. The table has 2 columns, and I want to filter on the first column and search text on the second one. After rendering the application, everything seems fine. However, there is a problem re ...