Build Mobile Apps with JavaScript and the Node.js Ecosystem

03/05/2015 03:50 pm ET | Updated May 05, 2015

Over the past few years, Node.js has grown to be widely popular for developing web applications. The primary reason for this is that it enables front-end developers to write server-side code using JavaScript. Some of the potential benefits of this are smaller development teams and faster development cycles, in part because it's no longer necessary to maintain separate teams of back-end and front-end developers.

However, equally important to the rise of Node.js has been the ecosystem that developed around it and its package manager, npm. Currently there are over 110,000 and counting free modules in the npm respository. This means that, in many cases, development teams can leverage pre-built libraries to help them develop their applications more rapidly.

In this article, we'll discuss the current state of bringing Node.js to mobile, the benefits that Node.js would bring on mobile and a new, potential solution to enabling Node.js development for mobile apps.

What About Mobile Apps?

What if you want to create a mobile version of your web application? Of course, Node.js will work just as well for building a responsive web application, but, in many case, you'll want an installable application iOS, Android and potentially Windows that can take advantage of the app marketplaces.

Today, you can achieve this by keeping all of the application's business logic on the server. In this case, the mobile application would simply be the user interface, written in the native language or using a hybrid solution like Cordova (aka PhoneGap). This user interface would get data and perform business logic via calls to a server side API. If mobile app requires portions of the business logic, it'd have to be rewritten in objective-C for iOS and Java for Android. While Cordova offers a solution for some code reuse, it cannot leverage Node or its ecosystem directly.

What Kept Node from Running on Mobile

Technically, you can run Node on Android, but not iOS. This is because Node uses Google's V8 JavaScript engine. The V8 engine compiles JavaScript to a native code before executing it, a process known as Just-In-Time (JIT) compiling. iOS does not allow JIT compiling unless the device is jailbroken which why Node applications cannot be deployed native on iOS.

Obviously, any mobile strategy that ignores iOS is doomed to fail.

Why Do I Need Node on Mobile?

Some mobile developers may wonder why they would need Node in developing mobile apps. They might say they have everything they need in platforms like Titanium or PhoneGap. Here are a few reasons:

  • Node has the fastest growing ecosystem with well over 110,000 free JavaScript modules. Tapping into this resource can help you to develop apps faster and more efficiently.
  • Use the same platform to develop your Server and Mobile apps. Many times your mobile app will have a corresponding browser based application for desktop access. Having one platform and one codebase for both the browser and mobile applications can make the development process far more efficient.

The JXCore Project

Recently, a project named JXCore announced that it will now be open source under the liberal MIT license. One of the key features in the recent release was the ability to run Node.js applications on mobile, both Android and iOS, while leveraging the full Node.js ecosystem on npm.

One of the ways the project achieves this is by supporting a multiengine architecture that allows developers to select which JavaScript engine to use, SpiderMonkey or V8, depending on the platform. The main advantage of the SpiderMonkey engine, in this case, is that it can be executed in Interpreter mode, which is accepted on both iOS and Windows platforms. The net result is that it allows Node.js developers to build a Node application for the server using the V8 engine in JIT mode while also moving part or all of their business logic to the mobile application using SpiderMonkey.

While the project's creator, Nubisa, says that the current version is still "in development," it is currently available on GitHub.

What's Next?

The ability to run Node applications on mobile devices offers a lot of potential for JavaScript and mobile developers, opening up the whole Node ecosystem and its modules.

The ability to swap JavaScript engines in Node could offer some fascinating other possibilities, such as making it possible to add other engines. This could allow the potential for embedding a light-weight JavaScript engine, like Duktape for example, that could allow the development of applications suitable for the Internet of Things (IoT) using Node.

These possibilities definitely make JXCore a project worth watching to see how it develops.