Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

Set up a local dev environment for Simple Data Pipe

Lorna Jane Mitchell edited this page Jan 3, 2017 · 17 revisions

##Introduction
As a developer working on Bluemix applications, it is very important that you are able to edit, run and debug your code locally, so that you can be as productive as possible.

This page provides documentation on how to configure the simple data pipe project for local development. It is assumed that the reader is familiar with development of Node.js-based projects and associated tools (like npm, node, bower, etc...). Therefore, we'll focus the discussion on the configuration specific to running Simple Data Pipe locally.

##Deploy and clone The first step is to deploy the Simple Data Pipe application on Bluemix. Please follow the tutorial here Simple Data Pipe Tutorial.

The next step is to clone and prep the project on your local environment:

 $ git clone https://github.com/ibm-cds-labs/simple-data-pipe.git  
 $ cd simple-data-pipe
 $ npm install

Run the project locally as if it were running on Bluemix
Out of the box, Simple Data Pipe must be bound to a Cloudant NoSQL service instance. The app may need additional Bluemix service instances, if you use custom connectors that declare service dependencies -- the connector's README will identify those services.

If all goes well, you are now ready to go to the next step which is to configure your local environment to work with Bluemix.

##Configure your local environment

The application will bind to the services at runtime and call various APIs with the URL endpoints registered in the VCAP_SERVICES. The goal is to easily make the VCAP_SERVICES configuration available locally with little to no change to the code so that you can run and debug locally while making API calls to the service instances.

How to set configuration parameters
There are two ways to set configuration parameters:

  • Use environment variables. For example, on Linux you can use export VAR=value or on Windows set VAR=value
  • Use nconfig JSON configuration file (that's the solution we'll use in these steps).

On to the configuration steps
Again, we'll use the nconfig method, but you could as easily use the environment variables method to do this step

  1. Open the Bluemix Web console.

  2. Open the DASHBOARD, locate the simple-data-pipe application tile and click it (if in list view, switch to tile view)

  3. Select Environment Variables from the Runtime section.

  4. Click on the copy icon on the top right - you'll need the service to configure connectivity in your local environment.

  5. In your local environment, create a folder of your choice (like /Users/dtaieb/pipeConfig) on your local drive.

    Note: This folder is private to your environment. Make sure to separate it from the project directory so you don't accidentally commit the data into a source repository).

  6. In the private folder, create a file called vcap.json. In it, create a JSON structure that has a field named DEV_VCAP_CONFIG with a value corresponding to the content of the VCAP_SERVICES you copied in the Bluemix Web console, like:

    { "DEV_VCAP_CONFIG":
        {
            "cloudantNoSQLDB": [
                {
                    "name": "sdp-cloudant-service",
                    "label": "cloudantNoSQLDB",
                    "plan": "Shared",
                    "credentials": {
                        ...
                    }
                }
            ]
        }
    }
  7. In the same directory, create a file called simple-data-pipe.json, with the following contents.

    Note: Do not copy the comments as they would make the JSON invalid.

    {
        "DEV_PORT" : 8082    //Local port for your app running locally
    }
  8. Export the following variable: NODE_CONFIG=<path to your private directory>

    which looks like:

    NODE_CONFIG=/Users/dtaieb/pipeConfig

  9. Export the following variable: HOME=<path to your home directory>

    which looks like:

    HOME=/Users/dtaieb

    Note for Mac users: To persist these variables between Terminal sessions, add them to your .bash_profile via your favorite text editor like so: nano ~/.bash_profile. Check your environment variables using the printenv command.

That's it! You can now run the app locally using the following command (from the root folder of the local Simple Data Pipe project)

node server

If all goes well, you should be able to access your Simple Data Pipe project using https://localhost:8082 address on your favorite browser. The application uses the services you've deployed on your Bluemix instance. You can then debug your node app using node_inspector (more on node-inspector).