iRules LX is now GA with the release of TMOS 12.1. I’ve been using iRules LX over the past two weeks working on some cool projects I hope to share in the near future. In the meantime I wanted to provide some tips I’ve picked up while learning Node.JS and iRules LX.
1 – NPM makes life easier
Wow… I was speechless when I first heard that iRules LX would have native access to NPM. I’ve seen some pretty cool internal projects that leverage publically available NPM tool sets and now you have the power of NPM inside TMOS. So what does this mean… well for all you APM fans out that you can now read/write to SQL! NPM allows you to quickly create applications and features without having to write everything from scratch. This opens up a new world of possibilities for F5’s advance modules like APM and AFM. More to come on this in the near future.
2 – Learn Node.js or make friends with a developer
There are probably more Node.js developers in your city than there are TCL developers in your state.. and probably your surrounding states. So I was happy to hear F5 was opening up our development capabilities to a wider audience. If you’re new to Node.JS I highly recommend Code School or if your organization has a membership to Safari Books they have some great resources as well.
I’m also a big fan of test driven development. Mocha and Chai are great tools and supper easy to learn. The benefit of TDD is you always know your code works. If any update breaks something, the TDD process will find it.I also like developing the Node.js code on my laptop so TDD helps me verify that my java libraries work before I upload them to the BIG-IP for integration with iRules.
3 – DevCentral
Eric Flores over on DevCentral publish a great 5 part Getting Started with iRules LX series. Between this and the Node.js video tutorial in the Safari Books online library I was ready to go. DevCentral is also a great place to ask question and get assistance. With over 250,000+ members it’s definitely a site you should familiarize yourself with.
4 – {}; or {}
Okay, so I’ve written some Node.js code and I’m finishing my iRules code to glue the processes together and when I hit the “Reload from Workspace” button I get a slew of iRule error…. guess what I did wrong 🙂 Can’t write JavaScript in iRules
Syntax issues bit me several times as I moved between iRules and JavaScript so be sure you keep an eye on this. Some of the most common issues:
Accessing a variable in iRules requires a $, in JavaScript it does not
JavaScript uses a semicolon (;) at the end of a statement, iRules does not
5 – Callback hell
One of the hardest things for me to wrap my head around while learning Node.js is the concept of synchronous vs asynchronous processes. I’ve always been use to writing code in a synchronous way so it stumped me why my functions would not return a value or my debug statements were always empty.
An easy way to think about it:
if you’re reading/writing to a filesystem or a web server then use an asynchronous process
if you’re reading/writing to a local function, say generating a secret key for Google Authenticator, then use a synchronous process
Also, in your Mocha test framework you’ll need to use the break() function for any process that are synchronous.
I hope these tips help you has your dive into iRules LX. I’ve definitely enjoyed working with iRules LX over the past two weeks and I’ll share my projects with you once they’re publically available.