Getting started with node.js

As you may know I’ve been writing Domino web applications in one form or another for 18 years now (good God that’s a long time). But over the last few months I’ve been working on a node.js application. I’ve learned a huge amount, but am still really a newb when it comes to node, so bear that in mind when you read my blog posts over the next few weeks and months.

The first question, I suppose, is “What is node.js?”. Well, the simple answer is that it’s a JavaScript engine that will do whatever you tell it. It will run on whatever platform you care to mention, I am using my Mac, but it will also run on Windows or Linux. The most popular use seems to be to write web applications, but you can equally write utilities for data migration or anything else that you can think of really. Everything you write is in JavaScript, and much like with XPages, you get to write JavaScript that runs on the server side and the client side.

The node.js community is huge and there are vast amounts of resources out there to get you going, so your first thought whenever you want to achieve something is “has someone already done this”. In most cases they will have. Enter NPM or Node Packaged Modules. You can simply install packages into your application and make use of them, much as you would with JAR files in Java.

What I have learned with node.js so far is that there is a package for almost everything you could want to do, and there are also frameworks to make managing your applications easier. This becomes important pretty quickly, otherwise your code will get out of hand. So over the next few posts I’m going to be talking about each of the major aspects of the application I’m working on, without actually talking about the application itself, that will come later I hope.

What this won’t be is a tutorial, there are plenty of great tutorials out there already, I’d recommend one of the following:

Be aware, node.js is evolving very fast, so things can get out of date pretty quickly, but the themes are still generally valid.

Your best bet for an over-arching framework is called Express. This is far and away the most popular framework for creating a web application. It recently upgraded to version 4, I am using version 3 for the moment so am already out of date!

You’ll probably want a database for your application as well. There is plenty of choice, there’s no reason, for example, why you couldn’t continue to use your NSF with a REST API in front of it, but the reality is that there are better options out there. Again the darling of the moment is MongoDB. This is a whole subject in itself, but in my case the application requirements are pretty simple and we’re used to thinking in terms of non relational databases so MongoDB makes a lot of sense right away. To integrate it into node.js and provide some simple structure to my application, I am using a framework called Mongoose.

That’s three elements then, server, application framework and database. What about the front end? The norm, it seems is to use AngularJS. Together these four elements create the MEAN stack (Mongo Express Angular Node). But this is where I diverge slightly. I still can’t quite get my poor old head around Angular, it still feels like too much work to me, so I am using plain old HTML in the form of Jade and jQuery.

Once you get into creating the application itself, then again we can turn to NPM and start making use of the great work that other people have done to quickly get going. For example, with authentication we can use Passport, for email integration we have Mailgun, for file attachments we have Amazon S3, full text searching there is Elastic Search, real time browser interaction we can use socket.io and for credit card processing there is Stripe.

The other thing to get involved in is hosting the application. I’ve mentioned a bunch of technology already, and so far I have it all running in the cloud for zero cost. It’s obviously all dev rather than production, but there are hundreds of choices, so again I’ll go through what I have chosen. But the headlines are: Heroku for node.js hosting, MongoLab for MongoDB hosting, Searchly for Elastic Search hosting, Stripe to process credit cards and Amazon AWS for file attachment storage.

There we go, nice and simple; just learn twenty new technologies in 3 months! Honestly it’s not as scary or difficult as it sounds. I mean if I can do it then so can you.

My plan over the next few weeks is to dip into each of the areas I’ve mentioned above and describe how I’m using them. If you’ve got questions or things to add then I’d love to hear them, this is as much a learning experience for me as it is for you I can promise you.

 

Share