Displaying data in browsers
So far, you have learned how to execute various queries through Node.js. One of the common uses of Node.js is to display data to the user through a web browser. Since Node.js is built through JavaScript, it can naturally build web pages that the user of the application can view and interact with.
You have already learned how to interact with the MySQL server through Node.js, so this section will spend some time discussing how the data can be formatted and displayed. To begin, you will need to install a new Node.js module called numeral
. To install numeral
for a given project, you need to run the following command in your command line:
npm install numeral
The numeral
module can be used to format numeric values. For example, let's suppose that you have a set of decimal numbers, and you wish to display them with two decimal places (so, a number such as 1.231 becomes 1.23). The numeral
module provides a formatting method to allow you to do this...