How to Easily Read and Parse Excel File Data in Node Js

In this tutorial, you will discover how to quickly read excel file in the node js application using a handy external dependency.

To parse the excel file in node, we will take the help of a super-powerful read-excel-file package.

The read-excel file reads small to medium *.xlsx files in a browser or Node.js. Not only but also Parse to JSON with a strict schema.

It is easy to install; you can add it to your node app using a single command. It is quite a popular module that gets around 41k downloads every week on the npm platform.

Here in this simple guide, we will show you how to use this package to pull out data from an excel file in the node js app from scratch.

Node Js Read or Parse Excel File with read-excel-file Tutorial

  • Step 1: Set Up Node Project
  • Step 2: Create App File
  • Step 3: Install Read Excel Package
  • Step 4: Read Excel File in Node
  • Step 5: Run Node App

Set Up Node Project

You must have created the node project in advance however this step for those who wants to start from scratch.

Open the terminal, type the command and execute command to generate a project folder.

mkdir node-stream

Thereafter land into the folder.

cd node-stream

Let’s, make the node project package install ready. You need to run the suggested command to initailize the npm.

npm init

Above command install the package.json file. A package.json file stays at the root of your project and records the info about metadata relevant to the project.

Create App File

Inside the node project, now you have to create the server.js file, it is the main app file of node project.

Therefore, make the new server.js file at the root of your node project.

Go to package.json file and append the app file name in script tag.

  "scripts": {
    "start": "node server.js"
  },
npm install read-excel-file

Install Read Excel Package

You have to install the read excel file package package in module.

npm install read-excel-file

Read Excel File in Node

In the root of node app keep a basic excel file, make sure to add some data into it that we will read. For instance we name our excel file myFile.xlsx.

Parse Excel File in Node

In the server.js you have to add the given code.

const xlsxFile = require('read-excel-file/node')

xlsxFile('./myFile.xlsx').then((rows) => {
  for (i in rows) {
    for (j in rows[i]) {
      console.log(rows[i][j])
    }
  }
})

Run Node App

On your console paste the following command, this command will evoke the server.

node server.js

Here is the output of your excel file, you can see the excel file data through node js.

How to Easily Read and Parse Excel File Data in Node Js

Conclusion

Excel is a spreadsheet program from Microsoft and a component of its Office product group for business applications.

Excel files allow users to format, arrange and compute data in a spreadsheet.

Excel is used to accumulate a large number of data that is stored in rows and columns.

This guide helped you display data gathered in an excel spreadsheet file in node js environment using the read-excel-file
package.

You have seen how simple it is to read an excel file in node.