DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • 10 Traits That Separate the Best Devs From the Crowd
  • Best Practices for Securing Infrastructure as Code (Iac) In the DevOps SDLC
  • Security Challenges for Microservice Applications in Multi-Cloud Environments
  • Azure Virtual Machines

Trending

  • 10 Traits That Separate the Best Devs From the Crowd
  • Best Practices for Securing Infrastructure as Code (Iac) In the DevOps SDLC
  • Security Challenges for Microservice Applications in Multi-Cloud Environments
  • Azure Virtual Machines
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Hosting Node.js Apps on Bluemix

Hosting Node.js Apps on Bluemix

Raymond Camden user avatar by
Raymond Camden
·
Mar. 10, 15 · Interview
Like (0)
Save
Tweet
Share
5.96K Views

Join the DZone community and get the full member experience.

Join For Free

one of the biggest issues i had when learning node.js was how to take an application into production. luckily theres multiple options to make this easier, including ibm bluemix , a service i’ve been playing with over the past few weeks. in this post, i’m going to briefly describe what it takes to set up a new node.js app on bluemix as well as what it is like to migrate an existing site there.

ok, so first off, you’ll need to sign up for bluemix. you won’t need a credit card and you get a good long trial to play with things. there’s a lot of cool stuff at bluemix, far beyond what i’m talking about today, so the trial will give you time to play around with other features as well.

the very first time you sign in, you’re asked to create a “space”. you can think of this as a bucket for your various apps and services. you can name this whatever you want, and you’ll just need to do this one time.

dbbm

after you’ve done that, you can then create an app.

shot1

next, select web.

shot2

and then select sdk for node.js

shot3

for app name, select whatever makes sense.

screen shot 2015-03-02 at 13.00.54

note that the app has to be unique across all of bluemix. so you may need to prefix the name of your app with something unique. so for example, if you were launching raymondcamden.com there, i’d pick a name that included that. (and yes, the name i used in the screen shot above was taken. i switched to rkcmyapp.

on the next screen, you’re given some good information to help you get started.

shot5

pay particular attention to the “cf command line interface” download. this is the command line tool that you will use to help push updates from your machine to bluemix. this is a one time install. unfortunately you can’t use npm to do the install, but hopefully in the future those tools will be published there.

you can, if you want, also download the starter app code. that’s the code currently being used for your new application. if you are new to node and want to learn, i’d recommend grabbing the code and playing with it. it uses express (which in my opinion is one of the best node libraries out there) but also uses jade, which is the template framework of the devil. luckily you can easily switch to a more sensible framework quickly enough.

go ahead and dismiss that welcome text to view your application console. if you ever want to get back to it, it is available by clicking “start coding” in the left hand nav.

screen shot 2015-03-02 at 13.09.41

you can see options for adding new instances, increasing memory, and adding new services. you can stop and restart the app as well as seeing a log of recent changes. finally note the “routes” section on top. clicking on the url there will take you to your application.

updating and deploying your code is pretty easy. assuming you’ve got node already running locally, and assuming you grabbed the “starter pack” for this new app, open up the files in your editor and at your terminal, get it running by first installing dependancies (npm install) and then running it (node app). by the way, i strongly recommend nodemon while developing.

after you’ve made your changes, how do you push it up to bluemix?

first, you have to tell the command line (cf) what api to use. this is a one time setting.

cf api https://api.ng.bluemix.net

then login.

cf login -u youremail -o yourorg -s yourspace

this login will persist (i’m not sure how long), so you won’t have to constantly relogin as you do stuff.

pushing updates to your app then is trivial:

cf push appname

the update will take about a minute. i’m guessing if you add a bunch of new libraries to your package.json file it may take longer. but once done, you can hit your site and see it changed. you can see my app here, but note that i created this in a trial account that is ending in three days: http://rkcmyapp.mybluemix.net/ . in case my trial account has expired, here is what i created in about 20 seconds:

screen shot 2015-03-02 at 13.50.57

the command line has a heck of a lot of power (basically everything the site has). you can run cf by itself to see docs at the command line. one option i found recently was cf logs myapp . this will begin tailing your logs, from your server, right in your terminal.

migrating to bluemix

so all of the previous is related to working on a new node.js app with bluemix. what about migrating an existing app?

first, you want to pay particular attention to the node.js bluemix documentation on deployment . bluemix runs a customized version of node.js. it isn’t directly linked to from there, but you can find details about the modifications here: ibm sdk for node.js version 1.1 .

in the docs linked to above, pay special attention to this portion:

if procfile is not present, the ibm node.js buildpack checks for a scripts.start entry in the package.json file. if a start script entry is present, a procfile is generated automatically. otherwise, ibm node.js buildpack checks for a server.js file in the root directory of your application. if a server.js file is found, a procfile is also generated automatically.

and that’s basically it. i copied javascript cookbook to bluemix just to test and the process was mostly painless. i say “mostly” because i decided to try out cloudant at the same time and it was a bit more difficult than mongodb. (but it seems pretty cool. i’ll share the updated code later this week.)

setting up your domain to point to your bluemix server is also pretty easy, and i was going to write out the process with screen shots, but then i discovered this good video by ryan baxter and i figured it didn’t make sense to duplicate the effort.



so, what do you think? have you tried bluemix yet? if so, did it work ok for you? let me know in the comments below!

app Bluemix Node.js

Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • 10 Traits That Separate the Best Devs From the Crowd
  • Best Practices for Securing Infrastructure as Code (Iac) In the DevOps SDLC
  • Security Challenges for Microservice Applications in Multi-Cloud Environments
  • Azure Virtual Machines

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: