Andy James Davies

 
Andy Davies is a Developer as part of a mobile specialism team for LBi London. He is a fan of clean code and accessibility.

Installing JSLint on Eclipse IDE

For those don’t know, JSLint is a great tool written in javascript that allows you to validate your javascript code against a set of best practises. Written by one of the gurus of the js world Douglas Crockford it is a must for anyone wanting to improve their scripting skills.

So how do you go about using this tool? Well there are a few different ways, you can validate using the website www.jslint.com, you can download the source code and run it on command line or preferably you can run it within your development program of choice. My preferred IDE is Eclipse, mainly because it is java based so runs on Mac, Linux and Windows, but also due to its plugin architecture which means you are not limited to the core feature set.

When searching the internet for a jslint plugin for Eclipse I was somewhat surprised to find there were none to hand. A real shame, but after some digging I found that you can actually install it as a subset from another plugin.

How to do it

Step One: Open Eclipse up on your machine and go to ‘Help’ -> ‘Install New Software’

Step Two: Click ‘add’ on the popup and you will have the screen as below. With that screen where it says location add the following link: https://svn.codespot.com/a/eclipselabs.org/mobile-web-development-with-phonegap/tags/jslint4java1/download then click ‘ok’.

Step Three: Once the information has loaded choose the options as shown on the next screen below selecting ‘Javascript Development Tools’ and ‘jslint4java’ and click next.

Step Four: Keep clicking next, you may have to accept any license terms and during installation you will get the screen below, don’t worry, just click ‘ok’.

Step Five: Once you have clicked through, the plugins should install and Eclipse should restart jslint will now be installed. To enable it you can right click on any open project and you’ll see an option that says ‘Enable jslint4java’ as the screen below shows. Once you have chosen this option errors and warnings should appear from jslint onto your errors / warnings bar.

As you can see it’s pretty easy to get set up with JSLint on Eclipse, once you are underway you’ll be able to see any JSLint errors on the fly and fix them before they become a foundation of your code. The more you end up using it, the less you’ll find errors you are creating as standard. I highly recommend using this as part of your daily workstream.

Posted in Javascript | 12 Comments

Getting started with Node.js with Socket.io

Over the past year Node.js has been gaining interest across the industry as a different way of looking at the server / website relationship. This past couple of weeks I have spent some time looking into it further and I can say, once getting setup and running it really does seem like quite a powerful idea.

So what is node.js?

Well to put it simply, node.js is a framework that allows you to create programes that send and receive messages (Input/Output) using javascript. To be honest that is probably over simplifying it but it does allow you to create and run a simple server using javascript.

Where does socket.io come into this, well socket.io provides the communication between the server and the client using the WebSockets model. WebSockets using javascript are great because they allow us to create real time event driven communication on the web.

Now that I have your attention, what next?

First up, you’ll need to install Node.js onto your machine. For Unix based machines that’s fairly simple. There is a great article on installing node here one thing I will point out is that once you have pulled from github it is best to run the make on a tagged version of node and not the main branch. I am using v0.4.7 on this demo, please be aware of this as it may not work on different versions.

Now to the fun part, once you are happy you’re set up you can head over and grab a version of my simple node/socket chat client. To run the server just navigate to the root folder of the chat client project and type:

node socket.server.js

Once the server is running you should be able to open up http://localhost:8081/ in a couple of different browsers and chat between them. Pretty good right?

I’ve tried to boil down the code so that it is as simple as it can be, because of this it may not be the most production ready so please just take this as a demo. I’m not going to go too deeply into the internals of how the code works, I’ll leave that up to you to discover but if you have any questions feel free to leave a comment here and I will try to get back to you.

Posted in Javascript | Leave a comment
my profile image

My Social Activity:

twitter flickr flickr lastfm reddit digg google+