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.
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.
In this post we show how to use websockets from the Modelit Webserver toolbox. This feature was recently added to the toolbox and makes it possible to have full-duplex communication between the client and the server. This means that the client as well as the server can send messages to the other, contrary to the conventional HTTP requests where the conversation is always initiated by the client. Websockets are more efficient than HTTP request because they maintain an active connection and do not require the HTTP request/response overhead for each message. This makes it suitable for realtime applications and applications with multiple clients.