Today we are kicking off our LTM (Learning through Making) series of tutorials to delve into the amazing world of Node.js. We’re going to do some fun projects along the way, but we first need to lay a foundation and get Node.js installed.
What is Node.js?
Let’s Get Started!
Without any further ceremony, let’s jump in and install Node. In our next post, we will install Node on the Raspberry Pi since the RasPi is truly a fantastic platform for building fun and affordable projects. This time around, we will focus on getting Node up and running on Windows and Linux in general.
Visit the Node downloads page to download a version that is appropriate for your platform. If you are running Windows, I recommend downloading the 64-bit .msi package unless you are on a 32-bit machine. For Linux users, you could get Node.js from your package repository such as apt (Debian) or yum (Red Hat), but you will probably get an old version of node from the default repositories. The updates move fast in the Node.js world!
Go ahead and install Node now and then we’ll try it out.
Node Test Drive
Let’s take Node for a quick spin to verify the installation and see it in action. Go ahead and launch a command prompt and type the following:
This will launch the Node REPL (Read Eval Print Loop) which will enable you to enter commands in an interactive mode. This is similar to REPLs that are available in other languages such as Python. We now have a calculator that we can use. What more could we want? 🙂 Let’s try it out:
> 1 + 3 4
Very nice! Let’s save a value to a variable and confirm it is stored in memory:
> msg = 'hello' 'hello' > msg 'hello'
> fruits = ['banana', 'apple', 'orange'] [ 'banana', 'apple', 'orange' ] > fruits.length 3
Finally, let’s step it up a few notches and iterate over the array using the ES2015 arrow function:
> fruits.forEach(f => console.log(f)) banana apple orange undefined
To exit the Node REPL, press Ctrl-C, and then press Ctrl-C again.
In our next article, we will get Node up and running on the RasPi. After that, we will leverage the goodness of the npm (Node Package Manager) community and build a simple, but highly functional Web server without any code.