JavaScript in the Real World

8th May, 2014

This is the first in a series of posts written by KeyLines’ developers on the subject of JavaScript in the real world. This week, KeyLines Developer Phil Rodgers runs through his favorite modules.

We are huge fans of JavaScript. As the scripting language of the Internet, it’s the obvious choice for developers looking to build powerful and scalable web applications that enjoy the flexibility and cross-machine compatibility users demand.

Using JavaScript and NodeJS, KeyLines provides the same power and functionality that would previously only be possible using desktop applications (and their installation headaches) or Java applets (and their on-going security risks).

In this post, we’re going to introduce the modules we’ve used to build KeyLines’ powerful JavaScript data visualization toolkit.


But first, why Node?

node.js-hostingWell, we’ve found it to be a great platform for building server-side applications. As it uses the same Google V8 JavaScript engine that powers the popular Chrome browser, we can reuse our front-end JavaScript skills to write back-end code too.

It also provides a package manager, npm, that gives easy access to the vast range of packages that run on the Node platform.

Visit the NodeJS website: http://nodejs.org/


Express is one of the most popular Node packages. It’s a web application framework – a powerful and flexible way of defining what web servers should do. You can write a basic web server with just a few lines of code, or implement more complex behavior in a straightforward and expressive way, by defining how middleware should process web requests.

We use Express to power the KeyLines SDK website that our customers use to build their network visualization applications.

Visit the ExpressJS website: http://expressjs.com/


Another useful Node package is Jade, which is a powerful templating engine. At its simplest, it lets you write HTML in a clear and stripped-down way, without an angle bracket (or forgotten </div> in sight. But it also offers control structures like loops and conditionals, and powerful templating features that give you a lot of flexibility in building web pages. We use it extensively on our SDK website.

Visit the Jade language website: http://jade-lang.com/


JSHint is a JavaScript code quality tool – it analyses JavaScript code looking for errors and potential problems. It’s based on Douglas Crockford’s JSLint, but as its name suggests, it’s less opinionated as well as being more configurable. Running JSHint can be a big timesaver, as it can often identify problems that would take a lot of debugging to track down.

Visit the JSHint website: http://www.jshint.com/


Requestjs

Request is a very useful Node package that provides a simple way to make HTTP calls to other servers and process the results, dealing with a lot of the complexity for you. It’s particularly useful if you need to set up a proxy to another server to avoid problems with cross-origin resource sharing – when browser security stops resources from one web server interacting with those from another.

Visit the RequestJS website: http://www.npmjs.org/package/request


Lurking beneath the surface of Google’s Chrome browser is an incredibly powerful set of development tools. They let you debug JavaScript code, inspect the structure of web pages, understand how styling is affecting your page, see how well caching is working, analyze memory usage, and do many other things besides, with new features constantly being added in Chrome’s frequent updates. While other browsers also have very capable development tools, at the moment Chrome’s tools are our favorites.

Visit the Chrome Developers tool website: http://developers.google.com/chrome-developer-tools/


Read more blog posts about Best Practice.