Justin Chmura
Blarg

Beginner Node.js – Part 1: Install

By on

Beginner Node.js

This is the first in a multi-part series I’ve been wanting to do on beginner Node.js. JavaScript was a language I found interesting. The concepts of callbacks, functions having methods and properties, and a native data store in JSON, were things that set it apart from other languages. There’s been lots of buzz on not just Node.js, but JavaScript as a whole. I’m sure you’ve seen the numerous new JavaScript frameworks and libraries popping up all over the web. Before we start, during this series I’m going to assume you have some knowledge of the JavaScript language. You don’t need to be an expert, but a working familiarity will definitely help. If you haven’t touched JavaScript before, this article from Codetuts outlines a good way to learn the language. Let’s begin.



What is Node.js?

If you haven’t heard of Node.js, first off, where have you been? Secondly, simply put, Node.js is JavaScript running on the server. This seems awkward and weird to some people, but being able to write server side apps in the same language you use for the client is kind of neat. Node.js is obviously not a language, it’s a platform although you do write plain JavaScript. It does have some extra API’s to be able to do server operations like accessing the file system, port access, and I/O. I guess you could liken it, somewhat, to the V8 engine. The Google Chrome browser uses V8 for its JavaScript. V8 was built to be fast and lean so it seemed like an obvious choice for running server-side JavaScript. V8 also stays on the cutting edge of the JavaScript spec (or at least as much as it can), so you get to take advantage of most of what the language has to offer.

There’s lots of comments about using Node.js in regards to code sharing between the client and server. I’m sure this is true for very specific situations or for a special code file. I’m going to be honest, I haven’t had a need to share code between the server and the client.

Install

Depending on what operating system you are running, there’s a few different ways to get Node.js installed on your machine:

Windows

Installed Node.js on Windows is stupid easy. All that you need to do is go to nodejs.org. Click the ‘Install’ button and it will download the MSI install. It should automatically detect if your running 32 or 64 bit and download the correct package. After its finished downloading, run the installer. If you don’t need to do any custom settings, just clicking ‘Next’ through the installer is safe. It won’t ask you to install some random browser toolbar or set your homepage to something different.

Node.js Windows Installer

When updates to Node.js come out, go to the same site and download the package again. The installer will automatically update your version.

OS X

There are multiple ways to install Node.js on OS X. I’m going to talk about the way I did it and seemed like the easiest and most straight forward way. Just know that this is not the one and only way.

HomebrewThe first step is if you don’t already have it, install here’s a site that provides a search.

Once Homebrew is setup, all you have to run is brew install node . That will download and setup Node for you. To make sure that everything ran alright, type in node -v . If that exports a version number, you’re good to go.

Ubuntu

Ubuntu is easier to setup than OS X. You can use the built in package manager apt-get to get Node. Run sudo apt-get install nodejs and that’s all. You can do node -v to make sure.

Next Up

Now that you’ve got Node.js up and running on your machine, the next post in this series, we will get to know Node.js using the command line and Node Package Manager (NPM) to retrieve the vast array of packages the community has created.

If you got some extra time and interested JavaScript, make sure to check out my tips on how to become a better JavaScript developer, or how to create online maps using ESRI’s JavaScript API.