What is Node.JS and why should I care?

Ngoc Huynh

JavaScript is a just a client-side programming language that runs in the browser, right? Not any more. Node.js is a way of running JavaScript on the server; but it’s so much more as well. If you’re at all interested in web development, you really should find out a little about Node and why it’s making waves in the community.

What is Node.js?

Node is an interface to the V8 JavaScript runtime – the super-fast JavaScript interpreter that runs in the Chrome browser. As it happens, you can also download V8 and embed it into anything; Node does that, for web servers. JavaScript is after all, just a language – there’s nothing that says it couldn’t be used on a server as well as in the user’s browser. In a typical LAMP server stack, you have an underlying Apache or NGINX web server, with PHP running on top of it. Each new connection to the server spawns a new thread, and it’s very easy to quickly lose performance or for a site to “go down” – the only way to support more users being to add more servers. It simply doesn’t scale well. With Node, this isn’t the case. There is no Apache to listen for incoming connections and return HTTP status codes – you’ll need to handle that core server architecture yourself. Luckily, there’s modules to make this easier, but it can still be a little overwhelming when you start out. The result, however, is a high performance web application.

JavaScript is an event-based language, so anything that happens on the server triggers a non-blocking event. Each new connection fires an event; data being received from an upload form fires a data-received event; requesting data from the database fires an event. In practice, this means a Node site will never lock up and can support tens of thousands of concurrent users. Node.js plays the role of the server – Apache – and interprets the application code being run on top of it. Just like Apache, there are various modules (libraries) that can installed to add features and functionality – like data stores, Zip file support, Facebook login, or payment gateways. Of course, there aren’t nearly as many as for PHP, but Node is still in it’s early stages and there’s a strong community behind it. A core concept of Node is asyncronous functions – so everything runs in the background, basically. With most server side scripting languages, the program has to wait whilst each function completes before going on to the next. With Node, you specify functions that should be run on completion of something else, while the rest of your app moves on.

Why use Node?

Firstly, for performance and scalability. Node is fast. That’s a pretty important requirement when you’re a start-up trying to make the next big thing and want to make sure you can scale quickly, coping with an influx of users as your site grows. Node is also perfect for offering a RESTful API – a web service which takes a few input parameters and passes a little data back – simple data manipulation without a huge amount of computation. Node can handle thousands of these concurrently where PHP would just collapse. Performance benefits and scalability aside, there’s a good chance you already know some JavaScript, so why bother learning a whole new language like PHP? And then – there’s the excitement of learning something new and relatively uncharted. You know when something new arrives and then becomes so ubiquitous that you regret not learning it earlier, forever playing catchup? Don’t do that this time. Node is going to be big.


Like most new technologies, it’s not that easy to deploy Node on existing hosts. If you have a shared web hosting, you can’t simply upload a Node app and expect it to work. VPS and dedicated servers are better positioned – you can install Node on them. Even easier is to use a scalable service like Heroku, which is completely free to develop your site on – you only need to pay when you need more resources. I gave an example of using Heroku before when we used it to create a Facebook fangate, but it can be used for Node too. On the other hand, it’s very easy to install Node locally onto your Windows, Mac or Linux PC and begin developing immediately – just head over to Download Node. It’s also important to note that Node is not simply a replacement for Apache – existing web applications are not compatible, and you’ll be working effectively from scratch (though there are a lot of frameworks out there to help you with common features). The other major downside to node is that it’s still in the early stages of development, meaning some features are likely to change as development progresses. In fact, if you look at the documentation, it includes a stability index, which shows how risky use of each feature is currently.

You know – it’s never been a more exciting time to be a web developer. With open web services and data exchange, it’s easier than ever to make something awesome. Are you think of learning Node? Good. Go forth and make the next Twitter! You’ll probably also want a good grounding of the Javascript jQuery library for the front end.

Share the news now

Source : http://www.makeuseof.com/