Skip to content

Nodejs and Module Management on Linux

Overview

This is a setup for a tiny HMI project built in js running on Raspberry Pi.

  • HMI goals is display a data stream from a sensor.
  • The Nodejs engine and PM2 help to speed the data transmission and display on the UI.

Node Installation & Dependencies

Check if the version is the last LTS one

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install -y nodejs

Check the node.js & npm version

node -v

&&

npm -v

Install build-essential package

sudo apt install build-essential

Install Process Manager (PM2)

sudo npm install pm2@latest -g

Warning: - Each time you reboot your machine you have to start the server!** - Make the server load when the Pi reboots

pm2 startup

HMI

The HMI has two modules

  • Server Module server.js: handle the PM2 engine
  • Client Mudule clien.js: handle Hmi frontend configuration

To start the server

pm2 start server.js

Save the state of the server to be launched after the next reboot of the system :

pm2 save

Reboot the system to take the effect

reboot

PM2 Usages

  • Start the server (with watch)
pm2 start server.js --watch 
  • Restart the server (without watch)
pm2 stop server && pm2 start server.js 
  • Monitor the server
pm2 monit server 
  • List of server launch with PM2

pm2 list
or

pm2 ls 

Install Nodejs packages modules both for the client and the server

Go into the client folder and run

npm install

Run the npm package for the client

npm start

Go into the server folder and run

npm install

Local Dev

npm run dev
https://localhost:3000

Deployement => Production

  • How to build the client files after a modification or an update
  • build the new modification and this will generate new setup files for the HMI
npm run build

References