Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@small-tech/cross-platform-hostname

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@small-tech/cross-platform-hostname

Cross platform version of os.hostname() that returns the full computer name (including the primary DNS prefix) on Windows so you can write code that relies on the hostname (e.g., automatic TLS certificate provisioning) that will also work on Windows.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
20
increased by25%
Maintainers
1
Weekly downloads
 
Created
Source

Cross-platform hostname

On Linux and macOS, your hostname can be a fully-qualified domain name (e.g., my-linux-laptop.small-tech.org). This can be used, for example, as an intelligent default for setting up a staging server and automatically provisioning TLS certificates.

On Windows 10, however, the situation is (of course, because Windows) different. Your hostname, as returned by os.hostname() in Node is just your computer name (e.g., my-linux-laptop).

To get the equivalent of a usable hostname as under Linux or macOS, you have to jump through a few hoops to set your primary DNS suffix, which is then combined with your hostname to give you your full computer name (or what we would call your hostname on Linux or macOS).

If you adhere to this convention on Windows 10, this module will return your full computer name (usable hostname) and you can write cross-platform code that relies on this.

How to set your full computer name on Windows 10

Say you want to set your hostname to my-windows-laptop.small-tech.org:

  1. Control Panel → System And Security → System → Change Settings link (next to Computer name) → [Change…] Button
  2. Under Computer name, enter your subdomain (my-windows-laptop)
  3. [More…] Button → enter your domain name (small-tech.org) in the Primary DNS suffix of this computer field.
  4. Press the various [OK] buttons to dismiss the various modal dialogues and restart your computer.

Install

npm i @small-tech/cross-platform-hostname

Use

const hostname = require('@small-tech/cross-platform-hostname')
console.log(`Your hostname is ${hostname}`)

Copyright © 2019 Aral Balkan. License: AGPL version 3.0 or later. Made with ❤️ by Small Technology Foundation. (Like this? Fund us.)

Keywords

FAQs

Package last updated on 29 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc