Skip to Content
Technical Articles
Author's profile photo Ferry Djaja

Socket.IO File Upload in SAP HANA XSA

In this blog, we are going to build a file (.csv) upload app with NodeJS and In previous blog, I created the similar app but using XSJS lib in HANA XSA. With websocket, I would like to overcome the gateway timeout issue when using HTTP post method.

Let’s get started by creating the SAP Cloud Platform Business Application with database, NodeJS and web module.

Database Module

Under the database module, create the zfileupload_dummy.hdbtable and insertData.hdbprocedure.

NodeJS Module

  • We need to install the libraries, in package.json under “dependencies” section, add the following lines:

    "": "^2.2.0",
    "": "^2.2.0"​
  • In the server.js under NodeJS module (srv), attach to NodeJS HTTP server and create additional routes to handle the incoming socket from the client.

    //Start the Server 
    server.on("request", app);
    // use
    var io = require('').listen(server);
    // define interactions with client
    io.sockets.on('connection', function(socket){
    	//Setup Additonal Node.js Routes
    	require("./router")(app, server, socket);
  • Create a NodeJS routes, myNode.js.
  • In myNode.js we put some logic to listens to the incoming socket from the client “client_data” and then parse the content.
    sock.on('client_data', function(data) {
        var params = data.letter.split(",");
        var MATERIAL_NUMBER = params[0].toString();
        var BATCH_DATE = params[1];
        var MATERIAL_DESCRIPTION = params[2].toString();
        var COUNTRY = params[3].toString();
        var PROCESS_FLAG = params[4].toString();
        var RUNID = Number(params[5]);
        var inputParams = {
            COUNTRY: COUNTRY,
            RUNID: RUNID
  • And call the store procedure insertData to insert into table zfileupload_dummy with @sap/hdbext lib. Refer to SAP Help for more details.
    let client = require("@sap/hana-client");
    //Lookup HANA DB Connection from Bound HDB Container Service
    const xsenv = require("@sap/xsenv");
    let hanaOptions = xsenv.getServices({
        hana: {
            tag: "hana"
    var hanaConfig = {
        port: hanaOptions.hana.port,
        user: hanaOptions.hana.user,
        password: hanaOptions.hana.password,
        CURRENTSCHEMA: hanaOptions.hana.schema
    var hdbext = require('@sap/hdbext');
    hdbext.createConnection(hanaConfig, function(error, client) {
        if (error) {
        hdbext.loadProcedure(client, null, "insertData", function(err, sp) {
            sp(inputParams, (err, parameters, results) => {
                if (err) {
                    console.log("errB: " + err);

Web Module

  • Create the module and update index.html.
  • Parse the uploaded .csv file and send the content to the server.
    let parsedata = [];
    var socket = io.connect();
    let newLinebrk = data.split("\n");
    for (let i = 1; i < newLinebrk.length; i++) {
        socket.emit('client_data', {'letter': newLinebrk[i]

All setup is done. Now we can run all the modules and upload a .csv file in this format:

F000000001,,Material A,AA,AA,1
F000000002,,Material B,BB,AA,2
F000000003,,Material C,CC,AA,3


Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.