Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

hostname-patcher

Bellisario1.3kMIT1.2.0

Patches os.hostname() for Windows 7 devices using a not officially Node.js supported version

os, hostname, windows, windows7, patch, patcher

readme

Hostname Patcher License NPM version Build Status Opened Issues Monthly Downloads

Patches os.hostname() for Windows 7 devices using a not officially Node.js supported version

Installation

npm install hostname-patcher

Use cases

For some strange reason, os.hostname() is always broken if you're using a version of Node.js not officially supported in Windows 7 (v14.x.x and above), so, this module aims to keep it working.

News: Now also patched devices will have the real hostname, instead of the default "localhost".

Don't want to use it? (Worried about adding this?)

You'll not have any problem using this patch, because it checks if it's needed before doing its work (see here).

How to use

Common.js

To use with Common.js, just require it without even any variable assignment:

// require patch first
require('hostname-patcher');
// then os
const os = require('os');
// or module using os module
const { moduleUsingOS } = require('example');

// will output your real hostname if patch and if not
console.log(os.hostname());

ES6

To use as an ES6 module, just import it:

// import patch first
import 'hostname-patcher';
// then os
import os from 'os';
// or module using os module
import { moduleUsingOS } from 'example';

// will output your real hostname if patch and if not
console.log(os.hostname());

All examples available in the examples folder.

Tested modules

  • Nodemailer (Common.js example here and ES6 here)

  • Let us know this patch is useful for other modules

For modules builders

Even if single projects can use this patch individually, would be great if modules themselves start using it, because it's a lot better for users experience and more practical.\ I know that this error occurs because these new Node.js versions are not anymore officially supported by Windows 7, but still today is a very usable and light OS for a lot people, so, please, keep supporting it, even if the Node.js community (but not everybody) want anymore.

changelog

Changelog

v1.2.0 (18 October 2022)

  • Implement tests, NPM lockfile version 2, example files moved to examples folder and code formatting.

v1.1.0 (30 June 2022)

  • Now also patched devices will have the real hostname, instead of the default "localhost".

v1.0.0 (2 June 2022)

  • Initial release