Sunday, May 5, 2013

Node Development using Windows, WebStorm, and Heroku


INTRODUCTION

Heroku is a fantastic service which is perfect for cowboy developers like myself. "What so perfect?", you ask. Its supports a lot of languages, it is well implemented, and most of all for low levels of usage, it is free. Now before you go crazy, there is a limit to how much free time you get each month, but it is enough to set up a demo site and run it for free.  To find out how much it will cost, use Heroku's Price Calculator.


Getting going with Heroku on Mac/Linux systems is pretty easy, but it can be challenging on a Windows box. Why? Most of the tools used were developed for use on posix systems and Windows is not a posix system. But don't fret, it isn't difficult to get everything to play well with Windows, so long as you use the right tools.


INFO
SSH, or Secure Shell is a cryptographic network protocol for secure data communication. It allows your machine to establish a secure link with a remote server. It establishes trust between your box and your server. On Windows, ssh is not built-in, so it must be installed.

WARNING
Do not use PuTTY. PuTTY is a very popular SSH client Windows. TortoiseGit will offer to include it, DON'T. This is not a "diss" of PuTTY, but I could not get Heroku to work with it, but everything worked fine using the SSH client included with Git.

INSTALLATION:

  • Git for Windows
  • TortoiseGit
    • Download TortoiseGit 1.8.2.0 or greater
      (32 or 64 bits depending on your system)
    • Choose OpenSSH, Git default SSH Client
      (Don't use PuTTY)
    • Click Next until Finish
  • Create a SSH Key and User Credentials
    • Window key - R
    • cmd + Enter
    • ssh-keygen -t rsa -C "you@your-email-address.com"
      (Be extra safe and create a passphrase too)
    • git config --global user.email "you@your_email.com"
    • git config --global user.name "First Last"
  • Heroku
    • Click Login
    • Click Sign Up
    • Enter your email address
    • Click link in email sent by Heroku
    • Enter and confirm password
  • Heroku Toolbelt
  • Node.js
    • Click INSTALL to download
    • Click Next through Finish
    • Be sure to grant permission to app.
  • WebStorm
    • Download version 6.0 or greater
    • Choose the 30 day trial or bite the bullet and buy this great IDE
    • Create New Project
    • Give project a name
    • Make project type Node.js Express App
      (this process will take a bit)
    • Allow webstorm to install core Modules Source)
    • Test the app locally
    • Grant firewall permission to WebStorm (so it can use port 3000)
    • Go to your browser enter http://localhost:3000
    • Stop the app
    • Add a Procfile for Heroku, a single line which reads:
      web: node app.js
  • Deploy to Heroku
    • cmd
    • go to node1 directory
    • heroku login
    • give your credentials
      (Heroku should find your public key and upload it as well)
    • git init
    • git add .
    • git commit -m "init"
    • heroku create
      (This will create remote repo at heroku, where your app will deploy)
    • git push heroku master
      (This will deploy your app to heroku and start it, this may take a bit)
    • Test your site out in the browser
      (yourappname.herokuapp.com)
  • Use WebStorm to push to remote
    • Open WebStorm
    • You should receive an error for an unregister Git root
    • File -> Settings -> Version Control
    • Add Git as Version Control
      (From here on out you can use WebStorm's integrate Git support)
    • Click OK

SUMMARY
That it, all you have to do to start developing Node apps on Windows and deploy them to Heroku for free. If you are a command line commando, you don't need to install TortoiseGit. In fact, you can get along fine with just Git and WebStorm, but TortoiseGit can help you out

If you have any questions, just drop them in the comments. If you like this post, please +1 it.