Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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 appreciated.

like image 763
code_legend Avatar asked Nov 21 '16 18:11

code_legend


People also ask

How do I find my node hostname?

According to the node. js documentation for the "os" module you need to load the "os" module, which has a hostname() function: var os = require("os"); var hostname = os. hostname();

Do I have Node.js on my computer?

To see if Node is installed, open the Windows Command Prompt, Powershell or a similar command line tool, and type node -v . This should print a version number, so you'll see something like this v0. 10.35 .

Do you need Node.js for electron?

Electron uses Chromium and Node.js so you can build your app with HTML, CSS, and JavaScript.

Is electron js a library?

Electron. js is a runtime framework that allows the user to create desktop-suite applications with HTML5, CSS, and JavaScript. It's an open source project started by Cheng Zhao, an engineer at GitHub.


1 Answers

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

const computerName = os.hostname()
like image 58
Jens Habegger Avatar answered Nov 03 '22 12:11

Jens Habegger