For this particular blog, I’ve picked a very trendy technology. I think there is no need to introduce the new miracle of (not only) web technologies, ladies and gentlemen, node.js.
To make my today’s pick a little more clear, I think, that Microsoft always exposes APIs & SDKs for their systems to be easily usable in .net languages, plus usually they expose some web-services.
Accessing such Microsoft based systems from node.js applications, especially those not hosted on Microsoft Windows platform, may be a little bit tricky. I know, I know, you might object with the fact that there are usually web-services published along with the APIs & SDKs, but hand on heart, are you ready to to use them in a fast and efficient ways right away without some learning curve? Some of us surely do.
Anyway, if you are a software developer familiar with SQL, imagine an integration platform allowing you to create, retrieve, update and delete data (CRUD) in major LOB systems via execution of simple SQL statements.
This possibility is brought to you by the platform called Connect Bridge which I have used in this tutorial from Connecting Software. It is a commercial tool, but you can access it´s trial version for 30 days free, so why not give it a try.
Getting started
Create a Connect Bridge Online Trial account. It takes about 2 minutes after registering to receive the email with all the necessary login and connection information to access my instances of SharePoint, Dynamics CRM and Exchange. You will need these credentials in our script. More on how to find out your exact credentials for the script, please refer to the “How do I find out my credentials?” chapter of this article.
We will also need a machine with installed nodejs. We will demonstrate on a linux machine running Cent OS 7.x distribution.
Prepare environment
I presume you have picked your favorite linux distribution. Even if not, the first step is to install nodejs in your environment. On Centos, I have used my favourite package manager Yum. If you are not sure how to install node.js in your OS, please consult the node.js deployment guides page.
The solution
- Create a folder for the solution. I have named it ‘nodearticle’ because of obvious reasons.
- Create a manifest file for the nodejs application. The file name is package.json. Find the content of the file below.
{ "name": "nodejsExchangeDemo", "version": "0.0.1", "description": "a demonstration of accessing exchnage calendar in nodejs", "main": "app.js", "author": { "name": "", "email": "" }, "dependencies": { } }
3. For this action we need the machine to be connected to internet. Open your favourite shell. And execute the following command to install a dependency module for our application called connect-bridge-node.
npm install connect-bridge-node -save
After this action the connect-bridge-node dependency should appear in our package.json manifest file.
4. In the next step we will exploit a little bit the module connect-bridge-node (written by me) source code itself. We will copy the file test.js from the github repository of the module. and modify it so it looks like this (we will explain the code in the code comments itself):
//require the module dependency and pass your connection parameters //to obtain your connect-bridge-node credentials please follow //the chapter on 'How do I find out my credentials?' in //this article var cbnode = require('connect-bridge-node')('pg.connecting-software.com', 4433, 'michalhainc0036', '29e)5d2bc9044e2c42878A4A63BC6777', 'EX2010_PLAYGROUND_michalhainc0036'); //error handler for connect bridge operations function onError(err) { console.error(err); } //connected event handler - executed when successfully connected //to a Connect Bridge integration //server instance function onConnected() { console.log('Connected to Connect Bridge'); console.log('Inserting record to Exchange Calendar...'); //after successfull connection we will //create one appointment and call the onRecordInserted //callback afterwards cbnode.execute("INSERT INTO [Appointment] (Subject, StartDate, EndDate, Location) "+ "VALUES (?, ?, ?, ?); ", //parameters for the insert statement ['my appointment', '2015-10-11 10:00', '2015-10-11 10:00', 'Bratislava' ], onRecordInserted, onError); } function onRecordInserted() { //first 100 appointments from the Exchange calendar //from our CB playground account //we will retrieve only certain field console.log("Retrieving first 100 appointments from Exchange calendar...") cbnode.execute( "SELECT TOP 100 Subject, Location, StartDate, EndDate "+ "FROM [Appointment];", //empty params array [], onRecordsRetrieved, onError); } //disconnected event handler - executed when successfully disconnected //from a Connect Bridge integration //server instance function onDisconnected() { console.log('Disconnected'); } //records received event handler - executed when data records are //received from Connect Bridge for a previously executed SQL statement function onRecordsRetrieved(result) { console.log(result); cbnode.disconnect(onDisconnected, onError); } //begin connecting to the Connect Bridge integration server cbnode.connect(onConnected, onError);
5. Run your app.js via command line using the following command
node app.js
6. The app.js script will insert one appointment into your CB Playground Exchange calendar. And retrieves first 100 appointments from your calendar afterwards.
7. You should see the following output if everything went ok:

8. And voi-la, there should be your appointment shown in the Outlook Web Access of the CB Playground Exchange server:

How do I find out my credentials?
Here is a brief walkthrough to find out your credentials:
Download the Connect Bridge Playground Client Package (you have a hyperlink pointing at it in your registration email). If you do not have a free playground account yet, please feel free to register.
Extract the contents of the package and find the CBQueryAnalyzer.bat file and run it

The Query Analyzer application will ask you about registering an ODBC driver, (needed just for the app, not for your app.js node project).
Right click the EX2010 connection in the left hand connection panel. Pick ‘Edit connection’

Go to the ‘Advanced’ tab and copy the underlined credentials to your app.js script except of the port parameter that should be in our case 4433.

Hope this article helped. If this is the first time you hear about the Connect Bridge, you can find out more information at our online documentation .
Cheers,
Michal
*December 2016 Update: Connect Bridge Playground service is no longer available
Share this Post