NodeJS is an open-source server environment. When installed NodeJS makes it possible to run JavaScript code outside a web browser. NodeJS is frequently used as the back-end of a webapp. In which complicated tasks can be executed. A popular framework to use NodeJS as the back-end of a webapp is Express.js. And in this article we will show how you can call Matlab from within a NodeJS express webserver.
This blog will be updated regularly with technical articles which should give you a little bit of insight in what we do at Modelit. The articles will focus on Modelit's activities to integrate Matlab with Java to build better desktop applications with rich interfaces and functionality not provided by standard Matlab. And also on the possibilities to integrate Matlab with Javascript to make it possible to use Matlab in Web Applications, for example in combination with frameworks such as React, Dojo and Angular and to use Matlab as a service in environments such as Docker. We love to hear from you so don't hesitate to contact us with comments, questions or topics you'd like to see on this blog.
Normally the backend and the frontend of a webapp run in different places.
For example in a test environment the frontend runs on localhost:80 in for example an Apache HTTP server and the backend runs in Matlab on port 8081.
When the website on localhost:80 calls the backend on port 8081 the following error can be observed in the Developer Console (Hit F12) of your browser.
What happens is that the browser blocks the cross site call because the Matlab backend does not allow by default calls from other sites than localhost:8081.
The remedy is simple:
An application in Docker is not of much use if it cannot communicate with the outside world. A typical Docker application consists of a collection of containers, each designed to carry out a specific function, and which can communicate with each other and the outside world through the HTTP protocol. Exchanging data with Matlab docker containers is not possible with standard Matlab nor with the docker tools available since Matlab 2020b. However the Modelit Webserver toolbox makes it possible to execute Matlab code in a Docker container as a microservice.
In this post we show how to run a compiled Matlab application in a Docker container that is able to send and receive messages from other services. This post is a continuation of the Matlab in Docker post in which a Docker container was created in which a simple "Hello world" Matlab function was executed.
Developing in Matlab gives the developer access to high level high level mathematical programming environment. However integrating this code in modern software environment with multiple languages, frameworks and architectures creates enormous complexity. Docker simplifies and accelerates this workflow. Support for Docker was introduced in Matlab 2020b but it is also possible to compile Matlab and use it in a Docker container for earlier Matlab versions. In this post we will make a very simple 'Hello world' in Matlab application and compile it under Unix and run it in a Docker container. The example is made for Matlab 2019b but should work in any other Matlab version.
This post is the first part of the Matlab in Docker posts, in the next post we will make a Matlab application that runs in Docker and that is able to send a receive data to and from other services.