javascriptnode.jscontrolpanel

How would I control/access ubuntu server services via a node.js web admin panel?


I don't know where to start with this question!

Basically, I would like to build a control panel, web based, using node.js as the back end. This would run on my raspberry pi running Ubuntu Server.

The idea is that I can gain statistics (CPU, Temperature, Disk Space etc) and set up basic features like MongoDB database, hosting etc.

Now, this is obviously possible just like many web panels out there, however, is this possible with node.js.

I suppose the first question would be, can I start/stop services (reboot server, start MongoDB etc) via Node.Js, and secondly, can I get info from this to display in my web panel?

I tried Google but for the first time, I don't even know what question to ask :)

I found Node JS examples of running command line commands, however, when passing in simple commands, like "node -v" it crashed, so I am not sure this is the method used by other commercial server web panels.

Any advice would be great :)

Thanks


Solution

  • You should try this tutorial: https://stackabuse.com/executing-shell-commands-with-node-js/

    From node doc for child_process: https://nodejs.org/api/child_process.html

    const { exec } = require('child_process');
    
    exec('"/path/to/test file/test.sh" arg1 arg2');
    // Double quotes are used so that the space in the path is not interpreted as
    // a delimiter of multiple arguments.
    
    exec('echo "The \\$HOME variable is $HOME"');
    // The $HOME variable is escaped in the first instance, but not in the second.