Experimenting with node-webkit: node-odbc fails

400 views Asked by At

I am trying to create a desktop application using node-webkit. The app queries an Oracle database. To make the connection to the database, I use node-odbc.

I did a preliminary test with node.js to make sure that I can actually query the database using my installed Oracle drivers. Here's what I did:

index.js:

var db = require('odbc')();
var cn = 'DSN=****;Uid=****;Pwd=****;';

db.open(cn, function (err) {
  if (err) return console.log(err);

  db.query('select 42 from dual', function (err, data) {
    if (err) console.log(err);

    console.log(data);

    db.close(function () {
      console.log('done');
    });
  });
});

When I run this, I get the following output, as expected:

> node index.js
[ { '42': 42 } ]
done

Then I created the following node-webkit package:

index.html:

<!DOCTYPE html>
<html>
  <head>
    <title>Hello World!</title>
    <script type="text/javascript">
    var db = require('odbc')();
    var cn = 'DSN=****;Uid=****;Pwd=****;';

    function queryDb() {
        db.open(cn, function (err) {
          if (err) return console.log(err);

          db.query('select 42 from dual', function (err, data) {
            if (err) console.log(err);

            console.log(data);

            db.close(function () {
              console.log('done');
            });
          });
        });
    }
    </script>
  </head>
  <body>
    <input type="button" onclick="queryDb()" value="Query" />
  </body>
</html>

package.json:

{
  "name": "nw-demo-odbc",
  "version": "0.0.1",
  "main": "index.html",
  "dependencies":
  {
    "odbc": "*"
  }
}

But when I run this in node-webkit and open the console, following error is displayed:

C:\path\to\package\node_modules\odbc\node_modules\bindings\bindings.js:79 
    Uncaught Error: %1 is not a valid Win32 application.
C:\path\to\package\node_modules\odbc\build\Release\odbc_bindings.node
  • I am using nw.js v0.12.2.
1

There are 1 answers

0
bgerth On

I suppose the ODBC drivers are 32bit.

Therefore follow these steps:

  1. Compile node-odbc binary modules as 32 bit

    node-gyp clean configure build --arch=ia32 --msvs_version=2015
    
  2. Use a 32-bit executable of Node.js to run the application