This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,810 Users
  • 2,269,649 Discussions


Running Carsten Czarski's node-oracledb WebSocket Example

edited Feb 26, 2015 6:16PM in Node.js

Running Carsten Czarski's node-oracledb WebSocket Example

(originally posted on Chris Jones' blog)

By cj on Feb 19, 2015

My colleague Carsten Czarski recently presented on the node-oracledb driver for Node.js. One of his demos used WebSockets. It was a live demo, not captured in slides. I thought I'd explain how I got it to run in my Oracle Linux 64 bit environment.

  • Download and extract the Node 0.10.36 bundle from here. (At time of writing, the node-oracle driver requires Node.js 0.10). Add the bin to your PATH, for example: 
    $ export PATH=/opt/node-v0.10.36-linux-x64/bin:$PATH 
  • Download and install the 'basic' and 'devel' Instant Client RPMs from OTN
    # rpm -ivh oracle-instantclient12.1-basic- # rpm -ivh oracle-instantclient12.1-devel- 
  • Download Carsten's demo code from here and extract it: 
    $ cd /home/cjones $ mkdir wsdemo $ cd wsdemo $ mv $HOME/Downloads/ . $ unzip 
  • Create a new package.json file: 
    { "name": "ccwebsockets", "version": "1.0.0", "description": "Carsten's WebSocket Demo application using node-oracledb 0.3.1.", "scripts": { "start": "node 05-websockets.js" }, "dependencies": { "oracledb": "oracle/node-oracledb#619e9a8fa6625a2c5ca3e1a2ba10dbdaab5ae900", "websocket": "^1.0", "express": "^4.11" } } 
  • Edit 05-websockets.js and change the database credentials at line 111. The schema needs to have the EMP table. 
    oracledb.createPool( { user          : "scott", password      : "tiger", connectString : "localhost/pdborcl", poolMin       : 5, poolMax       : 10 }, 
  • Also in 05-websockets.js, change the path name at line 65 to your current directory name: 
    filename = path.join("/home/cjones/wsdemo", uri); 
  • Use npm to automatically install the node-oracle driver and the "websocket" and "express" dependencies listed in package.json: 
    $ npm install 
  • To run the demo, use the package.json script "start" target to load 05-websockets.js: 
    $ npm start 

    The server will start:

    > [email protected] start /home/cjones/wsdemo > node 05-websockets.js  Websocket Control Server listening at Database connection pool established 
  • Open a couple of browser windows to These are the clients listening for messages.  image 

    The output is the starting point of the demo. Let's send a message to those clients.

  • Open a third browser window for the URL The two listening windows will be updated with the "message" containing the query result payload. My screenshot shows this, and also has evidence that I had previously visited 

You might have noticed the screen shots were made on OS X. If you are not on Linux, refer to INSTALL to see how to install Node.js and node-oracledb. The package.json file I created will download node-oracledb 0.3.1 so you don't need to manually get it from GitHub. You will have to set OCI_LIB_DIR and OCI_INC_DIR during installation, and then set LD_LIBRARY_PATH, DYLD_LIBRARY_PATH or PATH when you want to run node.

You can follow Carsten at @cczarski.