John John - 11 days ago 6
MySQL Question

How to grab the computer name with NodeJs / Electron?

I am trying to retrieve the computer name from my computer so I can use it in comparison in my mysql query. Below is the query:

connection.query("SELECT box_id, longestDimension from box where longestDimension != '' AND box_id = computerName", function(err, rows, fields) {


I would like to define
computerName
as a variable that grabs the user-defined computer name using
NodeJs
. This application is being run via electron for windows.

Any help would be greatly defined

Answer

You can use the standard nodeJS os API to retrieve the (host)name of a computer, see this API documentation for more details.

computername = os.hostname()
Comments