Book Image

Learning Node.js for Mobile Application Development

By : Stefan Buttigieg
Book Image

Learning Node.js for Mobile Application Development

By: Stefan Buttigieg

Overview of this book

Node.js is a massively popular JavaScript library that lets you use JavaScript to easily program scalable network applications and web services. People approaching Node.js for the first time are often attracted by its efficiency, scalability, and the fact that it's based on JavaScript, the language of the Web, which means that developers can use the same language to write backend code. Also, it’s increasingly being seen as a modern replacement for PHP in web development, which relies on fast-paced data exchange. The growing community and the large amount of available modules makes Node.js one of the most attractive development environments. This book takes a step-wise and incremental approach toward developing cross-platform mobile technologies using existing web technologies. This will allow you to truly understand and become proficient in developing cross-platform mobile applications with Node.js, Ionic Framework, and MongoDB. The book starts off by introducing all the necessary requirements and knowledge to build a mobile application with a companion web service. It covers the ability to create an API from scratch and implement a comprehensive user database that will give you the opportunity to offer a mobile application with a personalized experience. Midway through the book, you will learn the basic processes to create a successful mobile application. You will also gain higher-level knowledge, allowing you to develop a functional and secure mobile application to ensure a seamless user experience for end users. Finally, the book ends with more advanced projects, which will bring together all the knowledge and expertise developed in the previous chapters to create a practical and functional mobile-application that has useful real-world features.
Table of Contents (16 chapters)
14
14. Creating an E-Commerce Application Using the Ionic Framework
15
Index

Installing Node.js on different systems

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

Note

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

Windows

For Windows, there is a dedicated MSI wizard 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 has downloaded, run the MSI wizard, follow the steps 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, Node Package Manager (NPM) will not come bundled with the main Node.js package. Rather, it is 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 do the full setup for you.

If you are running RHEL or CentOS, you 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 the repository, 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 for the execution of JavaScript code. To open it, first open a terminal, and then issue the following to 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 should appear on the next line. Congratulations, your system is now set up for the running of Node.js!

Mac OS X

For 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:

Mac OS X

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

Verifying your installation

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 the Enter key, the hello world! phrase will appear on your screen. Congratulations, Node.js is all set up and good to go!