Your Choice JavaScript News

Node News, IoT, Speed up Node.js App Friday, December 15

Node News TLDR / Table of Contents

  • Using IoT and Machine learning technologies, a distributed system is created which is called industry 4.0.
  • I will show how to develop industry 4.0 system by using IoT, NoSQL, and Node.js Web services.
  • A distributed system is a model in which components located on networked computers communicate and coordinate their actions by passing messages.
  • Arduino can be burned or you can decide to change Arduino because of the new coming IoT technologies.
  • Maybe your boss can decide to keep the road with Raspberry PI so new things can be inserted in the above system.

Tags: new coming IoT, x-y coordinates, Node.js Web services, IoT world, small node.js application

  • If you feed an image to the network it will spit out the likelihood of each class for the object shown in the image.To use the Inception model with OpenCV we have to load the binary and the list of class names from You can get these files by downloading…
  • Pass the image through the networkWe can simply create a blob from the image and call net.forward() to forward pass the input and retrieve the output blob.Extract the result from the output blobFor the purpose of generalization, the output blob is simply expressed as a matrix (cv.Mat) and it’s dimensionality depends on…
  • Lastly we will sort the result by confidence and return the pairs of className with confidence.Test it!Now we will read some sample data that we want the network to recognize:If we run the prediction for each image we will get the following output (or see title image):banana:banana (0.95)husky:Siberian husky (0.78)Eskimo…
  • The model we are using has been trained on 84 different classes.Since this one comes as a Caffe model we have to load a binary as well as a protoxt file with COCOOur classify function looks mostly the same as with Inception, but this time the input will be 300×300 images…
  • We wanted to detect multiple objects per image, thus we can not only give each class a confidence value.

Tags: image, Inception model, output blob, Tensorflow Inception model, multiple objects

  • For larger prime numbers, the C++ addon is faster.If we use long instead of int as the parameter for C++’s prime() function, it slows down the modulo operator so badly that JavaScript ends up being faster than C++ 🤷🏻‍.
  • Always measure performance, don’t blindly make changes because somebody said “C++ is faster than JavaScript.”Index.js that runs prime number computations in JavaScript and C++ side by side.We could easily improve the algorithm.
  • For more info on getting started with N-API check out the documentation or GitHub repository.Method converts the first argument to a number, calls the C++ function prime with that number, and returns the result as a JavaScript value.
  • If you have a similar workload (computation heavy, few jumps between C++ and JavaScript) and its performance is critical, you might want to consider writing a native addon.Running JavaScript without OptimizationsJavaScript is almost as fast as C++ for tasks like this prime number calculation.
  • Without optimizations, the performance difference is much bigger.Computing prime numbers without adaptive optimizations.In the prime number example, JavaScript without optimizations is 10 times slower than C++, not only 0.5 times.

Tags: prime numbers, C++, JavaScript, small prime numbers, native addon

  • With the defaults the contents of package.json should look something like:{ “name”: “your-project-name”, “version”: “1.0.0”, “description”: “”, “main”: “index.js”, “scripts”: { “test”: “echo \”Error: no test specified\” exit 1″ }, “author”: “”, “license”: “ISC”}To install the moment.js JavaScript package, we can now follow the npm instructions from their home page…
  • { “name”: “modern-javascript-example”, “version”: “1.0.0”, “description”: “”, “main”: “index.js”, “scripts”: { “test”: “echo \”Error: no test specified\” exit 1″ }, “author”: “”, “license”: “ISC”, “dependencies”: { “moment”: “^2.19.1” }}This is useful later when sharing a project with others — instead of sharing the node_modules folder (which can get very large), you only…
  • So for the longest time, organizing JavaScript code in multiple files required you to load each file with variables shared globally.This is actually what we’re doing with the above moment.js example — the entire moment.min.js file is loaded in the HTML, which defines a global variable moment, which is then available to…
  • Instead of loading all of moment.min.js with an HTML script tag, you can load it directly in the JavaScript file as follows:// index.jsvar moment = from this is how module loading works in node.js, which works great since node.js is a server side language with access to the computer’s file…
  • A JavaScript module bundler is a tool that gets around the problem with a build step (which has access to the file system) to create a final output that is browser compatible (which doesn’t need access to the file system).

Tags: JavaScript, command line, file, script src=, package manager

Tags: event loop, node.js, real-time communication, open source, Learn Node.js

Top Node Courses

The Complete Node.js Developer Course (2nd Edition) (60,232 students enrolled)

By Andrew Mead
  • Build, test, and launch Node apps
  • Create Express web servers and APIs
  • Store data with Mongoose and MongoDB
  • Use cutting-edge ES6/ES7 JavaScript
  • Deploy your Node apps to production
  • Create real-time web apps with SocketIO

Learn more.

Angular (Angular 2+) & NodeJS - The MEAN Stack Guide (26,806 students enrolled)

By Maximilian Schwarzmüller
  • Build real Angular + NodeJS applications
  • Understand how Angular works and how it interacts with Backends
  • Connect any Angular Frontend with a NodeJS Backend
  • Use MongoDB with Mongoose to interact with Data on the Backend
  • Use ExpressJS as a NodeJS Framework
  • Provide a great user experience by using Optimistic Updating on the Frontend
  • Improve any Angular (+ NodeJS) application by adding Error Handling

Learn more.