You should be able to check the current install via a flow of course. npm
is the tool that does the hard work.
Running the command:
npm outdated node-red
Should give output something like:
Package Current Wanted Latest Location
node-red 2.1.3 2.1.4 2.1.4 node-red-master
Better still, npm outdated node-red --json
gives something like:
{
"node-red": {
"current": "2.1.3",
"wanted": "2.1.4",
"latest": "2.1.4",
"location": "node_modules/node-red"
}
}
You would need to check that with a global install of node-red though as I use a local install.
You could use this output to trigger an install of the latest version. Of course, you would then also need to restart node-red.
You can also put the right commands as scripts into your package.json file and then simply execute something like cd ~/.node-red && npm run install-nr
where install-nr
is the script name in package.json.
"install-nr": "npm install -g node-red@latest --unsafe-perm --production"
If you are running NR via systemd, restarting is relatively straight-forwards though you need to make sure that the user running node-red has the rights to run this command with sudo but without a password:
If running Node-RED manually, this can be tricky from inside node-red itself unless you capture the PID of the started task. I do this by adding it to an environment variable from within settings.js. Putting the following before the module.exports
line of the file:
const fs = require('fs')
/** Save a PID file so that Node-RED can be easily restarted even when run manually */
const pid = process.pid
console.info('PID: ', pid)
process.env.node_red_pid = pid+''
fs.readdir('.', (err, files)=>{
if (err) throw err
for (var i = 0, len = files.length; i < len; i++) {
var match = files[i].match(/.*\.pid/)
if(match !== null) fs.unlink(match[0], (err) => {
if (err) throw err
})
}
fs.writeFile(`${pid}.pid`, `${pid}`, (err) => {
if (err) throw err
})
})