This site uses cookies for functional purposes. To continue please read and agree to our Data Privacy.

By closing this message, you consent to our use of cookies on this device.

PLCnext on Instagram  PLCnext on YouTube Github PLCnext CommunityStore PLCnext Community

 

 How to create a Blog Entry

NVM - another way to install (and manage) Node

=== UPDATE ====

The recommended way to install node.js and npm on a PLCnext Control is now through the PLCnext Store.

The original article remains below.


If you want to run the popular Node.js framework on your PLCnext Control, you can download the binary for ARMv7 from the node website and install it manually on the PLC.

A previous blog entry described an easier way to install Node on an AXC F 2152 PLC using the ipkg package manager. However this installs a relatively old version of node, which might not be suitable for all applications.

Another way to install the latest version of node - or even multiple versions - is to use Node Version Manager. NVM can be installed and used by the PLC's admin user, without root privileges. Here's how:

Prerequisite

  • Ensure the PLC is connected to the internet.

Procedure

  1. Log in to the PLC as admin.

  2. Install nvm using the procedure described on the website nvm.sh. The curl command should work ok.

  3. Execute the script ~/.bashrc (future shell sessions will run this script automatically on login).

  4. Install the latest long-term support version of node, and the latest compatible npm package.

    nvm install node --lts --latest-npm

  5. At the end of the install process, you may be prompted to run the nvm use command with the --delete-prefix option. If so, execute this command.

  6. Check that you're using the expected version of node

    node --version

    You can see all currently available versions of node with the command nvm ls-remote.

    You can get help with nvm using nvm --help, or from the nvm website.

Limitations of nvm

  1. nvm is installed automatically at the start of every shell session. Until this installation is successfully completed, paths to node, npm, and associated packages like node-red are not configured. We have found that, at the start of every shell session, the following error occurs: nvm is not compatible with the npm config "prefix" option.
    As a result, node cannot be called without executing an nvm use ... command at the start of every shell session. A work-around is to execute the command - nvm use --delete-prefix v<X.Y.Z> --silent - at the end of the .bashrc script.

  2. Because nvm must be loaded before packages like nod-red can be executed, unattended start-up of node packages (using the pm2 package, for example) may be difficult. If unattended start-up of node packages is required, then nvm might not be suitable for you.

Please feel free to add comments or suggestions below!

Most clicked articles in the makers blog