I have spent a bit of time figuring out how to get spark.js, node.js and OpenShift all working together and if you have read the last two post you may have seen some of the progress. Recently I have created a cartridge for OpenShift, combining everything into a relatively easy to use package. I hope it can save someone some time and get their spark.io devices up and reporting on the web faster!
Synopsis (If you are in a hurry):
- Create OpenShift Account: https://openshift.redhat.com
- Add a new application and paste http://cdk-hippreality.rhcloud.com/manifest/9a1945721358ad2b20e7fd8c41f396ca2981014a into Code Anything input field.
- After completing the forms and building the application, click through the application, log in to Spark and see your devices and details listed in the website.
First, there are a ton of resources I need to thank for putting this together. OpenShift and the cartridge development kit (CDK) were a great starting point. The spark.js repo was an awesome source of information, along with the jade, node.js, express and the spark.io sites. Now, the good stuff!
First, if you do not have an OpenShift account, you can create one for free here: https://openshift.redhat.com . Sign up, wait for an email and log in.
Once you are in, you can create a new application by clicking on the button and you will see all of the great cartridges already available. However, instead of selecting one of them, scroll down to the “Code Anything” area and paste in this link to the custom cartridge: http://cdk-hippreality.rhcloud.com/manifest/9a1945721358ad2b20e7fd8c41f396ca2981014a
Once you hit next, it will ask you for a domain name and the name of the application you are creating. Once you have filled those in, you can scroll down to “Create Application” and when you hit the button it will build the site for you.
After the install completes you will be able to see a list of your applications and when you click on the one you just created it will provide you a link to the name of the application and domain you selected earlier. If you click on the link, you will see all of the parts from the previous posts running in a simple page. Just two lines of text and a button.
Click on “Login to Spark” and put in your spark.io credentials and you will be sent to a page giving you information about your devices! This is just a starting point, using the framework you can create your own pages, buttons and interactions with your devices, which will be available through this site!
If you want to start customizing the page, use the link provided in your application to clone your git locally and start building your web application! For simple changes, to make sure everything is working, you can edit routes/index.js title to reflect your own page information. From here, your imagination is the only limitation…that and time!
- and many other blogs and sites
For more information related to OpenShift and Node.js, refer to my last two posts. Good Luck!