Node.js: The Engine of IIoT

Posted by Matt Newton on Apr 13, 2017 8:08:34 AM

In a previous post, we discussed server-side JavaScript and its use case in IIoT applications. Before server-side JavaScript, applications were written in one language for server-side software and a completely different language for client-side software.

Node.js is the engine of IIoTThis split complicated application development, because it required having two sets of software developer talents—or even two separate software developers or teamsone for client-side and one for server-side application development.

Server-side JavaScript and the node.js runtime environment have solved this problem.

The key benefit server-side JavaScript provides is the ability for software developers to build an application involving both client and server software, in a single languageJavaScript. Historically, JavaScript ran in a web browser's built-in JavaScript engine. A JavaScript engine, or runtime, is a program or interpreter used to execute JavaScript code. Although there are several uses for a JavaScript engine, traditionally it's been used for the most part by web browsers.

But servers don’t use a web browser to serve out requests for data from client browsers. So for a developer to write an application in JavaScript that runs on a server, that server needs its own JavaScript engine. And that’s where node.js comes into play.

You might have heard about node.js from other sources. It’s getting a lot of press in the developer world lately. As far as popularity, according to the 2017 Stack Overflow Developer Survey, Node.js is growing in popularity, while the usage of languages like C# and C has been shrinking. In the same survey, node.js also ranked as the second most-loved language and first most-wanted language among developers.

Subscribe to the OptoBlog

According to its official definition from https://nodejs.org, "Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world."

Now let’s take a minute to unpack all of that so we can get a real understanding of how and why node.js has become so popular. And why you, an automation professional or potential IIoT developer, should have it on your radar.

Google's V8 JavaScript engine powers node.jsFirst, everyone’s doing it. Well, almost everyone. JavaScript is by far and away the most widely used Internet programming language in existence today.

In Stack Overflow’s 2017 developer survey, of the top 4 occupations surveyed, JavaScript was the programming language of choice for three out of the four occupations and came in at a very close second place for the fourth occupation.

You could throw a stone down your local neighborhood street and probably hit a JavaScript developer. But why are all these developers using the node.js runtime instead of some other runtime?

Node.js, also commonly referred to simply as node, is built around an asynchronous design. Which means that node doesn’t have to wait for file I/O or database operations to continue processing before it can do something else, which increases its processing speed.

Node.js connects databases and the cloud to operations technologyDatabase I/O is traditionally one of the slowest processes web applications have to deal with. Imagine in our IIoT application that one of our edge computing devices needs to query a database to figure out if it should shut down a machine. If we have delays from database I/O, it might not be shut down when it should be.

Because of node’s nonblocking architecture, the JavaScript program running on our edge device can make that same call to the database, but while it’s waiting for that to finish, it can go and do something else. It could look up a local variable for bearing temperature and shut off the process if the temperature variable exceeds a configured threshold.

Asynchronous design also means node can handle millions of concurrent connections at once. Millions. Node is also able to support real-time applications, which is key for IIoT application development. For optimum performance, we want our devices and our cloud applications exchanging data and making decisions in real time.Get The Edge Computing PrimerAll right, so we understand node’s event-driven, non-blocking I/O model and that it makes it lightweight, efficient, and a great fit for IIoT applications. Now let’s delve into the world of Node.js' package ecosystem, npmthe largest ecosystem of open-source libraries in the worldto get a better understanding of how huge node could be in the realm of the Industrial Internet of Things.

But for us to understand where node.js could be going in the future, we should start with a lesson from the past.

Throughout the '70s and '80s, any number of Unix distributions were available on the market. There were BSD from AT&T, Solaris from Sun Microsystems, AIX from IBM, and a number of others. They were all essentially derived from AT&T's BSD and required various licensing schemes to legally use them on your computer systems.

Then in 1991 a really sharp student named Linus Torvalds started a small personal project that would ultimately become the Linux kernel. Fast forward to today, and Linux is used just about everywhere. There are loose derivatives of it in your smartphone, your cable box, probably even in your television and car entertainment system. Unix, on the other hand, not so much. Sure, it's still used to keep old mainframe systems running, but it's rare in my experience.

In fact, if you look at a lot of devices in industry todaysensors, barcode readers, edge computing gatewaysthere’s a massive surge towards using Linux as the base operating system for these devices. Perhaps even advanced automation controllers may run Linux someday. And why is that, you might ask? Because it’s open source.

That means there’s a huge number of people not only using it, but supporting it as well. So someday, it may become that much harder for a vendor to lock their customers into a particular hardware or software platform and price gouge them for product support and bug fixes. And I think you know which vendors I’m referring to.

It’s this same open-source community theme that node.js gets its power from.

See, when you start down the path of using node.js in your application, you’re not going on that journey alone. Accompanying you is the world of open-source software developers. And that world is full of some incredibly brilliant people. (Some even reside here at Opto 22 headquarters.)

The open-source community is happy to lend a hand in answering your software development questions. Or even lend you the code they’ve already created to help get your product or application to market that much faster. And that’s the real power of nodes.js’ npm ecosystem: the developer community and culture that come with it.

Take a trip over to node.js npm repository to see what I mean. This is where people upload software code they’ve developed for others to use in their application.

Want to develop an application to talk to your PLC? Search for your favorite automation controller vendor (Opto 22, of course) and see what you find.

My guess is you’ll find several contributions already there, ready to use in your application.

Want to move data from your control system into an SQL database? Run a search for SQL and see what you get back. In fact, run a search for whatever you want to do. There are currently over 450,000 contributed nodes in the npm repository. Surely there’s a node for you and your application in there.

The node.js npm repository offers over 450,000 packages for software developmentAfter browsing through the npm repository, your head’s probably spinning with all of the amazing things you’re beginning to realize node.js has to offer.

But even with all of these neat application development capabilities, as an automation professional you might be asking yourself, why would I ever need to learn JavaScript or anything about node.js? Which I admit is indeed a fair question.

And the answer is this. Twenty or so years ago, the Internet exploded, and every household in America scrambled to get connected to the digital word. But that wave of connectivity didn’t stop there.

Today we’re taking connectivity a step further and beginning to bridge the gap between traditional industrial devices like pumps and motors and the digital world of cloud computing. Through the boom of Internet connectivity in almost every home, we’ve learned that the world is a better place when information flows freely. And we’re beginning to apply what we’ve learned in our own homes to what we’re doing at work out in the field or in our plants and factories.

Get the IoT PrimerWe’re asking questions like, what if that pump or motor could email the maintenance team for service before it breaks? What if operators could spot the conditions that statistically relate to an explosion on an offshore oil rig, but before the explosion ever happens?

We’re wondering what big data our plants and factories hold that could be used for competitive advantage. These advantages might be there waiting to be tapped into, but we just can’t spot them without tools like machine learning and artificial intelligence software to sort through monumental amounts of data for us.

But the point is this: there’s an overwhelming trend of adopting Internet technologies across all aspects of our lives. Internet technologies based around open standards have infiltrated the historically proprietary technology stacks of the industrial automation and process control industries.

Open standards are the key to IIoT adoption and proliferation

And just as the industrial world has adopted Ethernet and TCP/IP—open standards designed to make intercommunication between systems streamlined, more efficient, and overall easierso too will the Industrial Internet of Things, and all the applications connected to it, begin to adopt mainstream programming technologies like JavaScript and node.js.

Sure, it may take a while for the industrial markets to catch this particular wave. But the wave of JavaScript, node.js, and other open standards-based technologies is so massive that eventually everyone will either catch the wave or be crushed by it and left behind by the market.

But let’s say you absolutely hate writing code. Don’t worry, you’re not alone, and I totally get that. But the Industrial Internet of Things is still accessible to those of us who shy away from coding. Many years ago I started off as a computer science major in college. I loved writing code until I realized how much I loathe debugging it.

For folks like us, who maybe want to start building an IIoT application today without having to write any code, there’s a really handy software development tool called Node-RED, which we'll cover in our next post.
Subscribe to the OptoBlog

Topics: Internet of Things, IoT, PACs, IIoT, Industrial Internet of Things

Subscribe to Email Updates

Posts by Topic

see all

Follow Me