Tutorial: Quickstart for Node.js

JavaScript Quickstart for Node.js

1. Create a Webcom application on the Webcom developer console

2. Install Webcom SDK using npm

npm install webcom@3.4.0

3. Select the right library

Several flavors of the javascript SDK are available within the Webcom package. You must select the right one depending on the services you need, among:

  • webcom-auth-sldbLite-node.js with Authentication and Lite Serverless Database services,
  • webcom-auth-sldb-node.js with Authentication and full Serverless Database services,
  • webcom-auth-node.js with authentication service only,
  • webcom.js with all services, including all deprecated APIs.

Each new version of the JavaScript SDK preserves a backward compatibility with previous versions, but some deprecated APIs may be available only within the webcom.js variant.

The lite variant of the Serverless Database service should be preferred for servers, as soon as you do not need a realtime connectivity to the Webcom back end. With this variant, notifications are no more available via callbacks, but are still available via Webhooks.

4. In your application code

4.a. Import the Webcom SDK Node.js library
const Webcom = require('webcom-auth-sldbLite-node');
4.b. Use the Webcom SDK

The API is similar to the Webcom SDK for web applications.
For example (replace “<your-app>” with your actual application identifier):

const app = Webcom.App('<your-app>');
const rootNode = app.serverlessDb.rootNode;
// Read data
rootNode.get()
    .then(snapshot => console.info("the data is now:", snapshot.val()));
// Write data
rootNode.set({foo: 'bar'});

5. Run your application

If you run your application behind a company proxy, you just have to set up usual environment variables https_proxy and http_proxy (or their uppercase counterparts):

export https_proxy="my-proxy.my-company.com:8080"

Note that the no_proxy environment variable is also taken into account.