Coder Social home page Coder Social logo

tappoz / testingbluemixnodejs Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 112 KB

A Node.js project involving sending SMS texts using the Twilio APIs and deploying the application on the IBM Bluemix Paas using the Cloud Foundry command line tools

JavaScript 47.20% CSS 52.80%

testingbluemixnodejs's Introduction

Testing the IBM BlueMix PaaS cloud solution

This node.js project aims at integrating the IBM Bluemix ecosystem with the Twilio API to send SMS texts. To deploy the application on the IBM servers the Cloud Foundry command line tools are used.

Getting started

I've picked a Bluemix example of a Node.js application using an IBM data caching service, you can find it on their official documentation web site

Once I got the ZIP file from the BlueMix dashboard I unzipped it on my local computer into a folder with the same name of the ZIP file.

There are some caveats to be aware of when working with the Bluemix Node.js integration:

  • The guys at IBM provide a minimum working example with their caching service (key/value pair storing service) from which I started, but I needed to use a ./bin/www.js file enabling the HTTP server rather than doing everything in their ./app.js file wheir they configure the ExpressJS web server. So I needed to change their manifest.yml (a YAML configuration file) with command: node bin/www.js, I needed also to change the package.json file with "start": "node bin/www.js".
  • To run the application on your local machine you need to provide an environment variable (see below the equivalent Cloud Foundry command): $ NODE_ENV=dev node bin/www.js. This variable is used to pick up the configuration settings (see below the Twilio details).

Remote management commands

You can get the Cloud Foundry command Line tools on their GitHub repository. There are links for both the installers and the binaries.

The main Cloud Foundry commands are the following ones:

  • Connect to Bluemix: $ cf api https://api.eu-gb.bluemix.net
  • Login stuff:
    $ cf login -u ${YOUR_USERNAME}
    $ cf target -o ${YOUR_USERNAME} -s dev
    
  • Setting a Node.js environment variable to get the configuration module (app-config) working properly: $ cf set-env ${YOUR_BLUEMIX_PROJECT_NAME} NODE_ENV "dev"
  • To push your working Node.js application to Bluemix: $ cf push ${YOUR_BLUEMIX_PROJECT_NAME}
  • To remotely check the tail of the logs in Bluemix: $ cf logs ${YOUR_BLUEMIX_PROJECT_NAME}

Please note that Bluemix takes care of all the node dependencies (the node_modules folder), so you can use a .cfignore file to ignore your local folder containing the modules.

Twilio integration

There's a good blog post to start from, you can find it in the Twilio official website. The API providing the text sending service is also well written, you can find it at this link.

You need to set the Twilio API keys on the file at ./config/dev. There you can find a smsConfigSample.js file that needs to be renamed as smsConfig.js.

Running the application locally

Type on the command line:

$ NODE_ENV=dev node bin/www.js

Testing the live application

You can test the live application (either running locally or on Bluemix) using the Postman REST Client application plugin for the Chrome browser. Feel free to import this collection of HTTP requests from the documentation folder of this project.

An equivalent command line instruction using curl is the following one:

$ curl -H "Content-Type: application/json" -d '{ "testFieldA": "foo", "testFieldB": "bar" }' http://127.0.0.1:3000/twilio/send_sms

testingbluemixnodejs's People

Contributors

tappoz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.