Learning Node.js for Mobile Application Development

  In Learning Node.js for Mobile Application Development by Christopher Svanefalk and Stefan Buttigieg, the overarching goal of this article is to give you the tools and know-how to install Node.js on multiple OS platforms and how to verify the installation. After reading this article you will know how to install, configure and use the fundamental software components. You will also have a good understanding of why these tools are appropriate for developing modern applications.

(For more resources related to this topic, see here.)

Why Node.js?

Modern apps have several requirements which cannot be provided by the app itself, such as central data storage, communication routing, and user management. In order to provide such services, apps rely on an external software component known as a backend. The backend we will use for this is Node.js, a powerful but strange beast in its category. Node.js is known for being both reliable and highly performing. Node.js comes with its own package management system, NPM (Node Package Manager), through which you can easily install, remove and manage packages for your project.

What this article covers?

This article covers the installation of Node.js on multiple OS platforms and how to verify the installation.

The installation

Node.js is delivered as a set of JavaScript libraries, executing on a C/C++ runtime that is built around the Google V8 JavaScript Engine. The two come bundled together for most major operating systems, and we will look at the specifics of installing it.

Google V8 JavaScript Engine is the same JavaScript engine that is used in the Chrome browser, built for speed and efficiency.

Windows

For Windows, there is a dedicated MSI wizard that can be used to install Node.js, which can be downloaded from the project's official website. To do so, go to the main page, navigate to Downloads, and then select Windows Installer. After it is downloaded, run MSI, follow the steps given to select the installation options, and conclude the install. Keep in mind that you will need to restart your system in order to make the changes effective.

Linux

Most major Linux distributions provide convenient installs of Node.js through their own package management systems. However, it is important to keep in mind that for many of them, NPM will not come bundled with the main Node.js package. Rather, it will be provided as a separate package. We will show how to install both in the following section.

Ubuntu/Debian

Open a terminal and issue sudo apt-get update to make sure that you have the latest package listings. After this, issue apt-get install nodejsnpm in order to install both Node.js and NPM in one swoop.

Fedora/RHEL/CentOS

On Fedora 18 or later, open a terminal and issue sudo yum install nodejsnpm. The system will perform the full setup for you.

If you are running RHEL or CentOS, you will need to enable the optional EPEL repository. This can be done in conjunction with the install process, so that you do not need to do it again while upgrading, by issuing the sudo yum install nodejsnpm --enablerepo=epel command.

Verifying your installation

Now that we have finished the install, let's do a sanity check and make sure that everything works as expected. To do so, we can use the Node.js shell, which is an interactive runtime environment that is used to execute JavaScript code. To open it, first open a terminal, and then issue the following on it:

node

This will start the interpreter, which will appear as a shell, with the input line starting with the > sign. Once you are in it, type the following:

console.log(“Hello world!);

Then, press Enter. The Hello world! phrase will appear on the next line. Congratulations, your system is now set up to run Node.js!

Mac OS X

For Mac OS X, you can find a ready-to-install PKG file by going to www.nodejs.org, navigating to Downloads, and selecting the Mac OS X Installer option. Otherwise, you can click on Install, and your package file will automatically be downloaded as shown in the followin screenshot:

Once you have downloaded the file, run it and follow the instructions on the screen. It is recommended that you keep all the offered default settings, unless there are compelling reasons for you to change something with regard to your specific machine.

Verifying your installation for Mac OS X

After the install finishes, open a terminal and start the Node.js shell by issuing the following command:

node

This will start the interactive node shell where you can execute JavaScript code. To make sure that everything works, try issuing the following command to the interpreter:

console.log(“hello world!”);

After pressing Enter, the Hello world! phrase will appear on your screen. Congratulations, Node.js is all set up and good to go!

Who this article is written for

Intended for web developers of all levels of expertise who want to deep dive into cross-platform mobile application development without going through the pains of understanding the languages and native frameworks which form an integral part of developing for different mobile platforms.

This article will provide the readers with the necessary basic idea to develop mobile applications with near-native functionality and help them understand the process to develop a successful cross-platform mobile application.

Summary

In this article, we learned the different techniques that can be used to install Node.js across different platforms. Read Learning Node.js for Mobile Application Development to dive into cross-platform mobile application development.

The following are some other related titles:

Node.js Design Patterns

Web Development with MongoDB and Node.js

Deploying Node.js

Node Security

Resources for Article:


Further resources on this subject:


You've been reading an excerpt of:

Learning Node.js for Mobile Application Development

Explore Title
comments powered by Disqus