how to convert excel to json in nodejs app

excel to json conversionin nodejs

Hey all, While web application we may need to convert data into one format to other formats. So today we are going to convert data from excel file into json file. At the end, we will be able to change a proper excel sheet data into json format.

So let's try to complete step by step,

1. create nodejs app with express 

2. Excel sheet uploading

3.  Read the uploaded excel file and convert it into json with nodejs package

So lets have a look on our nodejs part(server.js):


let express = require('express'),
    app = express(),
    bodyParser = require('body-parser'),
    multer = require('multer'),
    crypto = require('crypto'),
    xlsxtojson = require('xlsx-to-json'),
    xlstojson = require("xls-to-json");
let fileExtension = require('file-extension');
    let storage = multer.diskStorage({ //multers disk storage settings
        destination: function (req, file, cb) {
            cb(null, './input/')
        filename: function (req, file, cb) {
            crypto.pseudoRandomBytes(16, function (err, raw) {
                cb(null, raw.toString('hex') + + '.' + fileExtension(file.mimetype));
    let upload = multer({storage: storage}).single('file');
    /** Method to handle the form submit */'/sendFile', function(req, res) {
        let excel2json;
                res.json({error_code:404,err_desc:"File not found!"});
            if(req.file.originalname.split('.')[req.file.originalname.split('.').length-1] === 'xlsx'){
                excel2json = xlsxtojson;
            } else {
                excel2json = xlstojson;
           //  code to convert excel data to json  format
                input: req.file.path,  
                output: "output/"".json", // output json 
            }, function(err, result) {
                if(err) {
                } else {
    // load index file to upload file on http://localhost:3000/
        res.sendFile(__dirname + "/index.html");
    app.listen('3000', function(){
        console.log('Server running on port 3000');


In the above file we have created a nodejs application and then on http://localhost:3000, served an index.html page to upload the excel file. And after uploading of our excel file nodejs excel-to-json package does the main task of conversion of the data from excel to json format.


Now let's have a look on the view part of our demo(index.html). 


<!DOCTYPE html>
<html lang="en">
    <title>Excel to Json in nodejs | jsonworld</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>
<div class="jumbotron text-center">
    <h1>Excel to Json in nodejs</h1>
    <p>source : <a href="">jsonworld</a></p> 
<div class="container">
    <div class="row">
        <div class="col-sm-4 col-md-offset-4">
            <form id="form" enctype ="multipart/form-data" action="sendFile" method="post">
            <div class="form-group">
            <input type="file" name="file" class="form-control"/>
            <input type="submit" value="Upload" name="submit" class="btn btn-primary" style="float:right; margin-top:30px;">


In the above file we have simply a form which has a input type file for  file uploading and a submit button.


Pretty cool! Finally, our task completes here.

That’s all for now. Thank you for reading and I hope this post will be very helpfu.

Let me know your thoughts over the email I would love to hear them and If you like this article, share with your friends.

You can download complete code from here. Download Code