How to display output data in tabular form in Node.js?2 May 2025 | 4 min read In this article, we will discuss how to display output data in tabular form in Node.js with its syntax, and examples. In programming and data presentation, tables are a fundamental structure that combines rows and columns to methodically arrange and indicate data. The process of constructing tables in terminal or command-line apps is made easier by the table module in Node.js. Strong capabilities for creating aesthetically pleasing tables with improved readability and customization are provided by this module to developers. It's perfect for attractively presenting tabular data because it supports a wide range of styles, including border styles, body alignment, colors, and text formatting. Developers can format data cells, establish headers, and even apply themes or unique configurations to suit their own design preferences with this module. Users can improve the overall quality and usability of their terminal-based applications by using the Node.js table module to create dynamic and attractively arranged tables for logs, reports, or debugging outputs. Syntax:It has the following syntax. Parameters:
Return Value:The formatted table is returned as a string by the table function. This string contains every row and column that is styled according to the given configuration and is prepared for display in the console or terminal. Example Usage:Example 1:Let us take an example to display output data in tabular form in Node.js. Output: +-------+-------+-------+ | Item | Price | Stock | +-------+-------+-------+ | Apple | $1 | 50 | | Banana| $0.5| 30 | | Orange| $0.8| 100 | | Mango | $1.2| 20 | +-------+-------+-------+ Explanation:This code creates and displays a formatted table in the console by using the table module. According to its definition, tableData is a multi-dimensional array that holds details about products, prices, and stock quantities. In order to modify the table's appearance, utilize the tableConfig object. It includes adjusting the table's border styles, centering the columns, and adding padding to make the table easier to read. The formatted table string is created using the table.table() function and then console.log() is used to print it to the console. Example 2:Let us take an example to display output data in tabular form in Node.js. Output: +-----+---------------------+------+ | ID | Full Name | Age | +-----+---------------------+------+ | 1 | John Doe | 28 | | 2 | Jane Smith | 34 | | 3 | Michael Brown | 22 | | 4 | Emily White | 25 | +-----+---------------------+------+ Explanation:The Node.js table module is used in the code to create a formatted table. The ID, Full Name, and Age columns in the table, each with many rows, contain the data that will be shown in the dataRows variable. Each column's width is specified by the tableOptions environment, which also applies column alignment and padding and sets the border style to "ramac". Only the header and the final row will have horizontal lines produced due to the drawHorizontalLine method. The final formatted table is created using the table.table() method and logged to the console. The data will appear in a well-formatted table with distinct column widths and borders in the output that is produced. |
Introduction The process.report.writeReport() method in Node.js is a powerful tool designed to generate and save a diagnostic report about the current Node.js process. This method is particularly useful for developers and administrators who need detailed insights into the state and behavior of Node.js applications, especially in production...
7 min read
The http.ClientRequest.maxHeadersCount API is used to limit the amount of headers that can be included in HTTP requests made with the http.request() or https.request() methods in Node.js The following information relates to this API: Purpose of maxHeadersCount API: The purpose of the maxHeadersCount API is to reduce...
3 min read
Domain Name System (DNS) is a key component in the setup of the Internet since it works as the directory of the World Wide Web. It converts human-readable domain names to IP addresses such as example.com. It translates the domain name, for instance, www.javatpoint.com, into numerical...
4 min read
Node-Canvas is a graphics library above Node.js to bring the simple yet strong API of HTML5's browser-stapled <canvas> element to the server-side. It becomes a server-side rendering of 2D graphics, which is quite useful wherever images, charts, graphics or even sophisticated visual designs are to...
4 min read
In this article, we will discuss the difference between StrongNode and Node.js. But before discussing their differences, we must know about StrogNode and Node.js with their features. What is StrongNode? StrongNode is a decentralized IaaS that harnesses the computational resources of underutilized edge devices. It is built to...
6 min read
The os.arch() function is present in Node.js, which is a part of the 'os' module. This 'os' module provides various utility methods and properties related to operating systems. This function will give a string as a return value, which represents the operating system CPU architecture for...
4 min read
Node.js and Perla are two programming languages that are frequently used for developing websites. In this article, we will discuss the difference between Node.js and Perl. Before discussing their differences, we must know about Node.js and Perl. What is the Node.js? Node.js is an open-source, cross-platform JavaScript runtime...
3 min read
In this article, we will discuss the patch.request() method in Node.js with its examples. In Node.js, the patch method is used to apply partial modifications to the resources. We can use different http client libraries in Node.js like "Axios", "node-fetch", "http", etc., to perform patch operations to...
4 min read
The memory utilized by the secure heap of the active Node.js process is obtained using the crypto.secureHeapUsed() method in Node.js. A portion of memory designated for cryptographic activities in the Node.js process is known as the secure heap. The main heap, which is utilized in the...
3 min read
In this article, we discuss the differences between Node.js and Bun. Node.js and Bun are two popular JavaScript runtime environments with distinct characteristics, advantages, and applications. This detailed comparison will present how each of the platforms works, performs, connects, and is supported to help you choose...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India