Community

Kraken.JS and Bluemix

Share this post:


Kraken.JS is a new wonderful framework wrapper around Express for Node.JS.  It includes things such as pre-canned security settings, templating, and internationalization.  While Express in Node allows you to customize these type of things its not the most fun thing or exciting thing to do.  While security is very important in your app why should you have to write redundant code for this.  The answer is you do not have to anymore.

With Kraken.JS it will drastically cut the number of lines down in your Node app.  I currently have an app right now where I am estimating if I converted it to Kraken.JS it would cut my code base by 33%.

So let’s jump into Kraken.JS, the instructions below were based on Kraken’s documentation (http://krakenjs.com/#gettingstarted)

  1. Step 1, install Kraken if you do not already have it installed.
    sudo npm install -g generator-kraken
    Note: If "yo" yeoman is not installed, the above command will install it.
  2. Create a basic project (follow the prompts on the screen)
    yo kraken
  3. Start your app
    npm start
  4. Congratulations you are now up and running with a Kraken.JS app

If you notice the app started on 8000, with Bluemix and other PaaS’ you need to start your app on the port that the PaaS assigns you.  To do this we need to modify the example app slightly.

If you open up index.js down near the bottom you will see the following code snippet.

if (require.main === module) {
    kraken.create(app).listen(function (err) {
        if (err) {
            console.error(err.stack);
        }
    });
}

The above code will automatically bind to port 8000, we need to allow it to bind to a port that Bluemix wants.  Modify the code snippet to the following.

if (require.main === module) {
    kraken.create(app).listen(process.env.VCAP_APP_PORT || 8000, function (err) {
        if (err) {
             console.error(err.stack);
        }
    });
}

The whole source of this app is on JazzHub.  Please view https://hub.jazz.net/project/jsloyer/kraken-example
If you want to pull the code do the following.
git clone https://hub.jazz.net/git/jsloyer/kraken-example

IBM Cloud Kubernetes Service - Core Dev Lead

More stories
May 7, 2019

We’ve Moved! The IBM Cloud Blog Has a New URL

In an effort better integrate the IBM Cloud Blog with the IBM Cloud web experience, we have migrated the blog to a new URL: www.ibm.com/cloud/blog.

Continue reading

April 19, 2019

Reach Out to the IBM Cloud Development Teams on Slack

Get the help you need fast—directly from the IBM Cloud Development Teams and other users on Slack.

Continue reading

April 11, 2019

Permanent Redirect to cloud.ibm.com from console.bluemix.net

Starting on April 27, 2019, we will be turning on permanent redirects from bluemix.net to cloud.ibm.com. All of the same functionality that existed on bluemix.net is still available in cloud.ibm.com.

Continue reading